From 39357e4f90414704d7c5d76ee0832c004b499dec Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 15 Nov 2014 19:40:42 +0100 Subject: [PATCH] wmaker: close unneeded file handles when running the bg helper (Coverity #50137) As pointed by Coverity, the file descriptor used in 'dup' to become the child process's STDIN is leaked, because it will not be used anymore, so we close it after the dup. Similarly, the file descriptors that represent the other ends of the pipe for each process are useless, so let's close them too to keep a reasonable number of opened file descriptors over time. Signed-off-by: Christophe CURIS Signed-off-by: Carlos R. Mafra --- src/misc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/misc.c b/src/misc.c index 096052ac..5d54561a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -945,6 +945,9 @@ Bool start_bg_helper(WScreen *scr) } else if (pid == 0) { char *dither; + /* We don't need this side of the pipe in the child process */ + close(filedes[1]); + SetupEnvironment(scr); if (close(0) < 0) @@ -952,6 +955,7 @@ Bool start_bg_helper(WScreen *scr) if (dup(filedes[0]) < 0) { werror("dup() failed:can't set workspace specific background image"); } + close(filedes[0]); dither = wPreferences.no_dithering ? "-m" : "-d"; if (wPreferences.smooth_workspace_back) execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL); @@ -961,9 +965,9 @@ Bool start_bg_helper(WScreen *scr) exit(1); } else { - if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) { - werror("error setting close-on-exec flag"); - } + /* We don't need this side of the pipe in the parent process */ + close(filedes[0]); + if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) { werror("error setting close-on-exec flag"); }