tun: linux: netlink sock needs cleaning up but file will be gc'd

This commit is contained in:
Jason A. Donenfeld 2019-02-27 02:20:17 +01:00
parent 366cbd11a4
commit 971be13e77

View File

@ -390,7 +390,6 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
_, err = tun.Name() _, err = tun.Name()
if err != nil { if err != nil {
tun.tunFile.Close()
return nil, err return nil, err
} }
@ -403,12 +402,11 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
tun.netlinkSock, err = createNetlinkSocket() tun.netlinkSock, err = createNetlinkSocket()
if err != nil { if err != nil {
tun.tunFile.Close()
return nil, err return nil, err
} }
tun.netlinkCancel, err = rwcancel.NewRWCancel(tun.netlinkSock) tun.netlinkCancel, err = rwcancel.NewRWCancel(tun.netlinkSock)
if err != nil { if err != nil {
tun.tunFile.Close() unix.Close(tun.netlinkSock)
return nil, err return nil, err
} }
@ -418,7 +416,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
err = tun.setMTU(mtu) err = tun.setMTU(mtu)
if err != nil { if err != nil {
tun.Close() unix.Close(tun.netlinkSock)
return nil, err return nil, err
} }