]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon: annotate "daemonisation" to help Coverity
authorVincent Bernat <vincent@bernat.ch>
Sun, 21 Mar 2021 11:05:16 +0000 (12:05 +0100)
committerVincent Bernat <vincent@bernat.ch>
Sun, 21 Mar 2021 11:05:16 +0000 (12:05 +0100)
When daemonizing, we need to use /dev/null for stdin, stdout, and
stderr. If one of these file descriptors happen to be already closed,
we need to close the new file descriptor only if > 2. This is
confusing confusing for Coverity, annotate it correctly.

Not all locations are annotated because not all of them are detected,
for some reason.

src/compat/daemon.c
src/daemon/lldpd.c

index 18f3d8d5f879028e7177bde55484141542627e40..79e0bb6fe4d93e9a7704566f5c7a2a8f343e4dd2 100644 (file)
@@ -62,5 +62,7 @@ daemon(int nochdir, int noclose)
                if (fd > 2)
                        (void)close (fd);
        }
+       /* coverity[resource_leak]
+          fd may be leaked if < 2, it's expected */
        return (0);
 }
index 5dd2413adf549222d1aaea6c5b0c4b77078c1598..1fc26db8db022b46e62c31316255aa6c2f076878 100644 (file)
@@ -1743,6 +1743,8 @@ lldpd_main(int argc, char *argv[], char *envp[])
                        dup2(fd, STDERR_FILENO);
                        if (fd > 2) close(fd);
                }
+               /* coverity[resource_leak]
+                  fd may be leaked if < 2, it's expected */
        }
        log_debug("main", "lldpd " PACKAGE_VERSION " starting...");
        version_check();