mirror of
https://github.com/vishvananda/netns
synced 2025-01-02 20:32:03 +00:00
fix: named ns handler may leak
This commit is contained in:
parent
a21f45a794
commit
358cc6be9e
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user