This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [RFA] Fix memory leak in windows_xfer_shared_libraries
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: "'Pedro Alves'" <palves at redhat dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Fri, 14 Dec 2012 08:53:06 +0100
- Subject: RE: [RFA] Fix memory leak in windows_xfer_shared_libraries
- References: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> <50CA3784.2030706@redhat.com>
> -----Message d'origine-----
> De?: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyé?: jeudi 13 décembre 2012 21:16
> À?: Pierre Muller
> Cc?: gdb-patches@sourceware.org
> Objet?: Re: [RFA] Fix memory leak in windows_xfer_shared_libraries
>
> On 12/13/2012 11:11 AM, Pierre Muller wrote:
> > --- windows-nat.c 13 Nov 2012 09:46:10 -0000 1.236
> > +++ windows-nat.c 13 Dec 2012 10:54:18 -0000
> > @@ -2411,11 +2411,11 @@ windows_xfer_shared_libraries (struct ta
> > buf = obstack_finish (&obstack);
> > len_avail = strlen (buf);
> > if (offset >= len_avail)
> > - return 0;
> > -
> > - if (len > len_avail - offset)
> > + len= 0
> > + else if (len > len_avail - offset)
> > len = len_avail - offset;
> > - memcpy (readbuf, buf + offset, len);
> > + if (len > 0)
> > + memcpy (readbuf, buf + offset, len);
> >
>
> You can avoid the last if by writing as:
>
> if (offset >= len_avail)
> len = 0;
> else
> {
> if (len > len_avail - offset)
> len = len_avail - offset;
> memcpy (readbuf, buf + offset, len);
> }
>
> I'd prefer that, but patch is okay either way.
I committed with your modification.
Thanks for the approval.
> > obstack_free (&obstack, NULL);
> > return len;
>
> >
> > I was also wondering if it would not be better to keep the obstack in
> > between the two calls, but that would probably require some static
> variable
> > :(
>
> That'd be fine. We actually do that in some cases in gdbserver, like
> handle_qxfer_threads and handle_qxfer_traceframe_info. It just didn't
> look like worth it enough to bother when I initially wrote this.
I was wondering if this would become a problem if we later add support for
multiple inferior
for windows-nat
I vaguely remember that I tried to achieve this a long time ago...
Anyhow, the memory leak is gone at least!
Pierre