diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-21 14:16:46 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-21 14:16:46 +0200 |
commit | 837a12c84151968fac6477f75d6bcb52e7ae64db (patch) | |
tree | 7d02bac68d391e3fe63882bc7dfca300530e6a59 /tun_linux.go | |
parent | 7472930d4e7b908646f87adf638188857566a7c6 (diff) |
Close events channel when no status listener
Diffstat (limited to 'tun_linux.go')
-rw-r--r-- | tun_linux.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/tun_linux.go b/tun_linux.go index f5b24dc..629a5ec 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -357,9 +357,13 @@ func (tun *NativeTun) Events() chan TUNEvent { func (tun *NativeTun) Close() error { var err1 error - close(tun.statusListenersShutdown) - if tun.netlinkCancel != nil { - err1 = tun.netlinkCancel.Cancel() + if tun.statusListenersShutdown != nil { + close(tun.statusListenersShutdown) + if tun.netlinkCancel != nil { + err1 = tun.netlinkCancel.Cancel() + } + } else if tun.events != nil { + close(tun.events) } err2 := tun.fd.Close() err3 := tun.fdCancel.Cancel() |