summaryrefslogtreecommitdiffhomepage
path: root/tun/tun_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'tun/tun_darwin.go')
-rw-r--r--tun/tun_darwin.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go
index a703c8c..35d3085 100644
--- a/tun/tun_darwin.go
+++ b/tun/tun_darwin.go
@@ -108,7 +108,6 @@ func CreateTUN(name string, mtu int) (Device, error) {
}
fd, err := unix.Socket(unix.AF_SYSTEM, unix.SOCK_DGRAM, 2)
-
if err != nil {
return nil, err
}
@@ -117,6 +116,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
copy(ctlInfo.Name[:], []byte(utunControlName))
err = unix.IoctlCtlInfo(fd, ctlInfo)
if err != nil {
+ unix.Close(fd)
return nil, fmt.Errorf("IoctlGetCtlInfo: %w", err)
}
@@ -127,11 +127,13 @@ func CreateTUN(name string, mtu int) (Device, error) {
err = unix.Connect(fd, sc)
if err != nil {
+ unix.Close(fd)
return nil, err
}
- err = syscall.SetNonblock(fd, true)
+ err = unix.SetNonblock(fd, true)
if err != nil {
+ unix.Close(fd)
return nil, err
}
tun, err := CreateTUNFromFile(os.NewFile(uintptr(fd), ""), mtu)