[PATCH] [xorg/xserver] os/client: Prevent rare fd leak in DetermineClientPid
Mark Kettenis
mark.kettenis at xs4all.nl
Thu Mar 24 07:18:17 PDT 2011
> From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= <erkki.seppala at vincit.fi>
> Date: Thu, 24 Mar 2011 15:46:39 +0200
>
> DetermineClientPid didn't close file descriptor if read on
> /proc/pid/cmdline failed. Added close to that path of code.
>
> Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
> Reviewed-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
> ---
> os/client.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/os/client.c b/os/client.c
> index 1311855..5c05f9b 100644
> --- a/os/client.c
> +++ b/os/client.c
> @@ -140,8 +140,10 @@ 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));
> - if (totsize <= 0)
> + if (totsize <= 0) {
> + close(fd);
> return;
> + }
> if (close(fd) < 0)
> return;
> path[totsize - 1] = '\0';
Actually, checking the return value of close(2) is fairly silly, at
least in this context. So you could write this as:
totsize = read(fd, path, sizeof(path));
close(fd);
if (totsize <= 0)
return;
Cheers,
Mark
More information about the xorg-devel
mailing list