This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] fix dirent resource leak in gdbserver/linux-low.c
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Cc: Michael Snyder <msnyder at vmware dot com>, Vladimir Prus <vladimir at codesourcery dot com>
- Date: Sun, 27 Feb 2011 17:00:59 +0000
- Subject: Re: [RFA] fix dirent resource leak in gdbserver/linux-low.c
- References: <4D6999AF.9080501@vmware.com>
On Sunday 27 February 2011 00:24:15, Michael Snyder wrote:
> opendir.txt
> 2011-02-26 Michael Snyder <msnyder@vmware.com>
>
> * linux-low.c (list_threads): Call closedir for dirent.
>
> Index: linux-low.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
> retrieving revision 1.168
> diff -u -p -u -p -r1.168 linux-low.c
> --- linux-low.c 6 Jan 2011 00:14:09 -0000 1.168
> +++ linux-low.c 27 Feb 2011 00:21:14 -0000
> @@ -4549,6 +4549,7 @@ list_threads (int pid, struct buffer *bu
> }
> }
> free (core_numbers);
> + closedir (dir);
> }
If the 'stat' ever fails for some reason, you're calling
closedir on a garbage pointer. I'm surprised coverity didn't
catch that. Put the the closedir call at the end of
the 'if (stat(...))' block instead. Okay with that change.
--
Pedro Alves