]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: darwin: write routeSocket variable in helper
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 18 Apr 2019 22:53:19 +0000 (07:53 +0900)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 18 Apr 2019 22:53:19 +0000 (07:53 +0900)
Otherwise the race detector "complains".

tun/tun_darwin.go

index 2077de361d98ac1db0e8fa7413587d82cf109f41..2afe9de80cccc0acfba176205170cf823f222dc9 100644 (file)
@@ -47,7 +47,10 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) {
                statusMTU int
        )
 
-       defer close(tun.events)
+       defer func() {
+               close(tun.events)
+               tun.routeSocket = -1
+       }()
 
        data := make([]byte, os.Getpagesize())
        for {
@@ -292,7 +295,6 @@ func (tun *NativeTun) Close() error {
        if tun.routeSocket != -1 {
                unix.Shutdown(tun.routeSocket, unix.SHUT_RDWR)
                err2 = unix.Close(tun.routeSocket)
-               tun.routeSocket = -1
        } else if tun.events != nil {
                close(tun.events)
        }