From 2e304488fac220fa205780a80533a2b955ee6b6d Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 21 Mar 2021 12:05:16 +0100 Subject: [PATCH] daemon: annotate "daemonisation" to help Coverity 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 | 2 ++ src/daemon/lldpd.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/compat/daemon.c b/src/compat/daemon.c index 18f3d8d5..79e0bb6f 100644 --- a/src/compat/daemon.c +++ b/src/compat/daemon.c @@ -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); } diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 5dd2413a..1fc26db8 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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(); -- 2.39.5