fix: named ns handler may leak

This commit is contained in:
Junhuang Hong 2022-12-08 10:53:50 +08:00 committed by Jeff Widman
parent a21f45a794
commit 358cc6be9e

View File

@ -65,6 +65,7 @@ func NewNamed(name string) (NsHandle, error) {
f, err := os.OpenFile(namedPath, os.O_CREATE|os.O_EXCL, 0444)
if err != nil {
newNs.Close()
return None(), err
}
f.Close()
@ -72,6 +73,7 @@ func NewNamed(name string) (NsHandle, error) {
nsPath := fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), unix.Gettid())
err = unix.Mount(nsPath, namedPath, "bind", unix.MS_BIND, "")
if err != nil {
newNs.Close()
return None(), err
}