From ef1e068d55f2247ff416204cebbbb96063a175c2 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 29 Mar 2024 15:14:55 +0100 Subject: [PATCH] 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. --- pdns/misc.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.47.2