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: [PATCH] solib_open, memory leak


On Mon, 06 Aug 2007 15:28:28 -0700
Jim Blandy <jimb@codesourcery.com> wrote:

> Even if you've made sure that temp_pathname is malloc'd by the time we
> reach the 'open', any later 'openp' call will throw away its value.
> openp is careful to store *something* in the pointer referred to by
> its last argument, even on error.
> 
> I think the invariant should be that, when found_file becomes >= 0,
> then temp_pathname is malloc'd, and not before.  The 'openp' clauses
> will preserve that.  So I think you need:
> 
>   if (found_file >= 0)
>     temp_pathname = xstrdup (temp_pathname);
> 
> after the 'open'.
> 
> And then there's no need for the xstrdup at the bottom; just return
> temp_pathname, or xfree it if the caller doesn't want it.

Jim's analysis looks right to me.

Kevin


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