From 58403f841526600ab8a899b0a3265d368a9209bd Mon Sep 17 00:00:00 2001 From: He Sun Date: Thu, 23 Apr 2020 20:23:20 +0800 Subject: [PATCH] Fix panic when dropping unix socket When a unix socket only calls function listen, its object is not created but its status becomes listening. At this time closing the socket would cause a panic before this commit. --- src/libos/src/net/unix_socket.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libos/src/net/unix_socket.rs b/src/libos/src/net/unix_socket.rs index 45421793..5fc2808e 100644 --- a/src/libos/src/net/unix_socket.rs +++ b/src/libos/src/net/unix_socket.rs @@ -286,8 +286,10 @@ impl UnixSocket { impl Drop for UnixSocket { fn drop(&mut self) { if let Status::Listening = self.status { - let path = &self.obj.as_ref().unwrap().path; - UnixSocketObject::remove(path); + // Only remove the object when there is one + if let Some(obj) = self.obj.as_ref() { + UnixSocketObject::remove(&obj.path); + } } } }