]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
FDWrapper: Do not try to close negative file descriptors
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Mar 2024 14:14:55 +0000 (15:14 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Mar 2024 14:14:55 +0000 (15:14 +0100)
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

index 7798ada49b056d39a67120c7719d126a32295a21..61116f20ab8f62f3ead33b0b7f5c3e65907028a0 100644 (file)
@@ -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;
     }