From: Remi Gacogne Date: Fri, 29 Mar 2024 14:14:55 +0000 (+0100) Subject: FDWrapper: Do not try to close negative file descriptors X-Git-Tag: rec-5.1.0-alpha1~67^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef1e068d55f2247ff416204cebbbb96063a175c2;p=thirdparty%2Fpdns.git FDWrapper: Do not try to close negative file descriptors It turns out that some of the BPF helper functions return a negative `errno` value in case of failure, and since we wrap the return value into a `FDWrapper` right away this led to a warning from Valgrind about trying to close an invalid file descriptor. --- diff --git a/pdns/misc.hh b/pdns/misc.hh index 7798ada49b..61116f20ab 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -803,7 +803,7 @@ struct FDWrapper FDWrapper& operator=(FDWrapper&& rhs) noexcept { - if (d_fd != -1) { + if (d_fd >= 0) { close(d_fd); } d_fd = rhs.d_fd; @@ -824,7 +824,7 @@ struct FDWrapper int reset() { int ret = 0; - if (d_fd != -1) { + if (d_fd >= 0) { ret = close(d_fd); d_fd = -1; }