]> 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>
Tue, 2 Apr 2024 09:44:24 +0000 (11:44 +0200)
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.

(cherry picked from commit ef1e068d55f2247ff416204cebbbb96063a175c2)

pdns/misc.hh

index cd7e607ef1c784fd6a087c1456f3c4f4e8d94d91..46e93f7ec15ad7c45f381e8e6c4c97fbc531713f 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;
@@ -823,7 +823,7 @@ struct FDWrapper
 
   void reset()
   {
-    if (d_fd != -1) {
+    if (d_fd >= 0) {
       ::close(d_fd);
       d_fd = -1;
     }