From 26fe256c14c5d7b98682c6497e733c4a2dde9921 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 13 Jul 2023 17:58:51 +0200 Subject: ipcpd: Fix leaked filedescriptors in ipcpd-udp Found by GCC static analyzer. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/udp/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ipcpd/udp/main.c') diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index b2170e0b..ee7e2f8f 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -712,7 +712,7 @@ static int udp_ipcp_bootstrap(const struct ipcp_config * conf) /* NOTE: Disgusted with this crap */ static int ddns_send(char * cmd) { - pid_t pid = -1; + pid_t pid; int wstatus; int pipe_fd[2]; char * argv[] = {NSUPDATE_EXEC, 0}; @@ -726,6 +726,8 @@ static int ddns_send(char * cmd) pid = fork(); if (pid == -1) { log_err("Failed to fork."); + close(pipe_fd[0]); + close(pipe_fd[1]); return -1; } @@ -733,6 +735,8 @@ static int ddns_send(char * cmd) close(pipe_fd[1]); dup2(pipe_fd[0], 0); execve(argv[0], &argv[0], envp); + log_err("Failed to execute: %s", strerror(errno)); + exit(1); } close(pipe_fd[0]); @@ -779,7 +783,9 @@ static uint32_t ddns_resolve(char * name, pid = fork(); if (pid == -1) { log_err("Failed to fork."); - return 0; + close(pipe_fd[0]); + close(pipe_fd[1]); + return -1; } if (pid == 0) { @@ -789,6 +795,8 @@ static uint32_t ddns_resolve(char * name, close(pipe_fd[0]); dup2(pipe_fd[1], 1); execve(argv[0], &argv[0], envp); + log_err("Failed to execute: %s", strerror(errno)); + exit(1); } close(pipe_fd[1]); -- cgit v1.2.3