Re: Fix for PR 10736

Sergio Durigan Junior
2010-03-31T21:20:32Z

Hi Pedro,

On Tuesday 30 March 2010 07:44:25, Pedro Alves wrote:
> > + /* Should we re-read the XML info for this target? */
> > + if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
> > + {
> > + /* The data-directory changed from the last time we used it.
> > + It means that we have to re-read the XML info. */
> > + have_initialized_sysinfo = 0;
> > + xfree (my_gdb_datadir);
> > + my_gdb_datadir = NULL;
>
> The previous data dir is only released if the datadir changed.
>
> > + if (sysinfo)
> > + free_syscalls_info ((void *) sysinfo);
> > + }
> >
> > +
> > + /* Saving the data-directory used to read this XML info. */
> > + my_gdb_datadir = xstrdup (gdb_datadir);
>
> So here my_gdb_datadir leaks if the datadir _doesn't_ change.
> I think you just need to move the xfree and my_data_dir=NULL
> statements outside the `if', before the early return.

Sorry, I don't know if I understood. If the datadir doesn't change, the call
to xstrdup will only be made once (i.e., when `have_initialized_sysinfo' is
zero). After that, it will never be called again unless datadir changes.

Thanks,