]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
rwcancel: add an explicit close call
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 19:18:21 +0000 (20:18 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 19:19:14 +0000 (20:19 +0100)
This lets us collect FDs even if the GC doesn't do it for us.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/sticky_linux.go
ipc/uapi_linux.go
rwcancel/rwcancel.go
tun/tun_linux.go

index 594cd01c2e54e0aa104c7682b534931b5193e3c1..a984f249a87f1bcea768fd7ba4cb521e06cb8073 100644 (file)
@@ -49,6 +49,7 @@ func (device *Device) routineRouteListener(bind conn.Bind, netlinkSock int, netl
        var reqPeer map[uint32]peerEndpointPtr
        var reqPeerLock sync.Mutex
 
+       defer netlinkCancel.Close()
        defer unix.Close(netlinkSock)
 
        for msg := make([]byte, 1<<16); ; {
index 3213543d54ddd7a22484d10ff21c27c086ab796d..e03a00b34b530a2a246f0fbe8d8983c8028fa1e2 100644 (file)
@@ -99,6 +99,7 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
        go func(l *UAPIListener) {
                var buff [0]byte
                for {
+                       defer uapi.inotifyRWCancel.Close()
                        // start with lstat to avoid race condition
                        if _, err := os.Lstat(socketPath); os.IsNotExist(err) {
                                l.connErr <- err
index 8a6300a28dd47496c5317773ad67e92ff05cdeae..70eb4ca0ec5de9c7778b5597af4204190e9e0e04 100644 (file)
@@ -119,3 +119,8 @@ func (rw *RWCancel) Cancel() (err error) {
        _, err = rw.closingWriter.Write([]byte{0})
        return
 }
+
+func (rw *RWCancel) Close() {
+       rw.closingReader.Close()
+       rw.closingWriter.Close()
+}
index be36c6989d8c0b8af27368ad5b27e3ba5a47960d..501f3a3108bd71495c488ba6d8fe77835d766ac1 100644 (file)
@@ -106,6 +106,7 @@ func (tun *NativeTun) routineNetlinkListener() {
                unix.Close(tun.netlinkSock)
                tun.hackListenerClosed.Lock()
                close(tun.events)
+               tun.netlinkCancel.Close()
        }()
 
        for msg := make([]byte, 1<<16); ; {