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.
This commit is contained in:
He Sun 2020-04-23 20:23:20 +08:00 committed by Tate, Hongliang Tian
parent 9815523a95
commit 58403f8415

@ -286,8 +286,10 @@ impl UnixSocket {
impl Drop for UnixSocket { impl Drop for UnixSocket {
fn drop(&mut self) { fn drop(&mut self) {
if let Status::Listening = self.status { if let Status::Listening = self.status {
let path = &self.obj.as_ref().unwrap().path; // Only remove the object when there is one
UnixSocketObject::remove(path); if let Some(obj) = self.obj.as_ref() {
UnixSocketObject::remove(&obj.path);
}
} }
} }
} }