os/client: Prevent rare fd leak in DetermineClientPid

DetermineClientPid didn't close file descriptor if read on
/proc/pid/cmdline failed. Adjusted the code to disregard the close
return value and perform the return after that, if the read failed or
returned EOF.

Signed-off-by: Mark Kettenis <mark.kettenis@xs4all.nl>
Signed-off-by: Erkki Seppälä <erkki.seppala@vincit.fi>
Reviewed-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Erkki Seppälä 2011-03-25 10:38:23 +02:00 committed by Keith Packard
parent cb5d4b416a
commit 2ef4ff45ef

View File

@ -140,10 +140,9 @@ void DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
/* Read the contents of /proc/pid/cmdline. It should contain the
* process name and arguments. */
totsize = read(fd, path, sizeof(path));
close(fd);
if (totsize <= 0)
return;
if (close(fd) < 0)
return;
path[totsize - 1] = '\0';
/* Contruct the process name without arguments. */