summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorErkki Seppälä <erkki.seppala@vincit.fi>2011-03-25 10:38:23 +0200
committerKeith Packard <keithp@keithp.com>2011-03-27 18:16:36 -0700
commit2ef4ff45ef1fcfc4967ebe3d550408769e5f6500 (patch)
treebe51732e040fc817232cecea3674343850dcab21 /os
parentcb5d4b416a0fc850a1c119755a9cc3c4f0d7a545 (diff)
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>
Diffstat (limited to 'os')
-rw-r--r--os/client.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/os/client.c b/os/client.c
index 1311855d5..b5349778b 100644
--- a/os/client.c
+++ b/os/client.c
@@ -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. */