mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 20:38:08 +01:00
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 <christophe.curis@free.fr> Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
e16c6fbf2a
commit
39357e4f90
10
src/misc.c
10
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user