Fix nil pointer exception in error handling (#696)

In case if the wgctrl.New() return with err, should not close the
resource.
This commit is contained in:
Zoltan Papp 2023-02-21 10:50:34 +01:00 committed by GitHub
parent 2f0b652dad
commit c3ed08c249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,12 +127,10 @@ func interfaceFilter(blackList []string) func(string) bool {
wg, err := wgctrl.New()
if err != nil {
log.Debugf("trying to create a wgctrl client failed with: %v", err)
return true
}
defer func() {
err := wg.Close()
if err != nil {
return
}
_ = wg.Close()
}()
_, err = wg.Device(iFace)