This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] fix dirent resource leak in gdbserver/linux-low.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]