From e1926a99d8cd93990aa86ed300c93e33c302b1e6 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 21 Mar 2021 15:25:19 +0100 Subject: [PATCH] client: fix additional memory leaks detected by Coverity Scan --- src/client/conf-system.c | 2 ++ src/compat/daemon.c | 4 ++-- src/daemon/lldpd.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/conf-system.c b/src/client/conf-system.c index 0764ed83..9524d0db 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -209,6 +209,7 @@ cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, if (value && strlen(value) == 1 && value[0] == '.') { if (uname(&un) < 0) { log_warn("lldpctl", "cannot get node name"); + lldpctl_atom_dec_ref(config); return 0; } value = un.nodename; @@ -280,6 +281,7 @@ cmd_bondslave_srcmac_type(struct lldpctl_conn_t *conn, struct writer *w, if (value == -1) { log_warnx("lldpctl", "invalid value"); + lldpctl_atom_dec_ref(config); return 0; } diff --git a/src/compat/daemon.c b/src/compat/daemon.c index 79e0bb6f..cf7f81d5 100644 --- a/src/compat/daemon.c +++ b/src/compat/daemon.c @@ -55,6 +55,8 @@ daemon(int nochdir, int noclose) if (!nochdir) (void)chdir("/"); + /* coverity[resource_leak] + fd may be leaked if < 2, it's expected */ if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); @@ -62,7 +64,5 @@ 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 efc06c80..a7b2647b 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1740,14 +1740,14 @@ lldpd_main(int argc, char *argv[], char *envp[]) /* So, we use syslog and we daemonize (or we are started by * systemd). No need to continue writing to stdout. */ int fd; + /* coverity[resource_leak] + fd may be leaked if < 2, it's expected */ if ((fd = open("/dev/null", O_RDWR, 0)) != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); 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