From 971be13e773f133a0a5ab08957725b43452202e2 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 27 Feb 2019 02:20:17 +0100 Subject: [PATCH] tun: linux: netlink sock needs cleaning up but file will be gc'd --- tun/tun_linux.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tun/tun_linux.go b/tun/tun_linux.go index 8dcad6b..0ee9f6c 100644 --- a/tun/tun_linux.go +++ b/tun/tun_linux.go @@ -390,7 +390,6 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { _, err = tun.Name() if err != nil { - tun.tunFile.Close() return nil, err } @@ -403,12 +402,11 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { tun.netlinkSock, err = createNetlinkSocket() if err != nil { - tun.tunFile.Close() return nil, err } tun.netlinkCancel, err = rwcancel.NewRWCancel(tun.netlinkSock) if err != nil { - tun.tunFile.Close() + unix.Close(tun.netlinkSock) return nil, err } @@ -418,7 +416,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { err = tun.setMTU(mtu) if err != nil { - tun.Close() + unix.Close(tun.netlinkSock) return nil, err }