cherry-pick: 3987 Fix nil pointer dereference

Merge in DNS/adguard-home from 3987-fix-nil-deref to master

Updates #3987.
Updates #2846.

Squashed commit of the following:

commit d653e09ce88a8b10b2a17fea1563c419895c714c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Dec 23 20:08:51 2021 +0300

    all: log changes

commit c47a4eeacf76fa7df2d01af166dee9d52528ac58
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Dec 23 19:22:39 2021 +0300

    aghnet: fix windows tests

commit 9c91f14ccfe967ada3c00ddb86d673238e52c12d
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Dec 23 19:09:49 2021 +0300

    aghnet: imp code readability, docs

commit d3df15d1892e4ebfe7f8ea7144e39a0c712fce52
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Dec 23 18:47:28 2021 +0300

    aghnet: fix nil pointer dereference
This commit is contained in:
Eugene Burkov
2021-12-24 22:36:08 +03:00
committed by Ainar Garipov
parent d280151c18
commit 7528699fc2
5 changed files with 58 additions and 3 deletions

View File

@@ -187,7 +187,8 @@ func GetSubnet(ifaceName string) *net.IPNet {
return nil
}
// CheckPort checks if the port is available for binding.
// CheckPort checks if the port is available for binding. network is expected
// to be one of "udp" and "tcp".
func CheckPort(network string, ip net.IP, port int) (err error) {
var c io.Closer
addr := netutil.IPPort{IP: ip, Port: port}.String()
@@ -200,7 +201,11 @@ func CheckPort(network string, ip net.IP, port int) (err error) {
return nil
}
return errors.WithDeferred(err, closePortChecker(c))
if err != nil {
return err
}
return closePortChecker(c)
}
// IsAddrInUse checks if err is about unsuccessful address binding.