This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] Fix other memory leak in solib_target_current_sos
- 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 11:25:57 +0100
- Subject: [RFA] Fix other memory leak in solib_target_current_sos
- References: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> <50CA3784.2030706@redhat.com> <000301cdd9d0$0db345d0$2919d170$@muller@ics-cnrs.unistra.fr> <50CAF521.3040307@redhat.com>
> -----Message d'origine-----
> De?: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyé?: vendredi 14 décembre 2012 10:45
> À?: Pierre Muller
> Cc?: gdb-patches@sourceware.org
> Objet?: Re: [RFA] Fix memory leak in windows_xfer_shared_libraries
>
> On 12/14/2012 07:53 AM, Pierre Muller wrote:
>
> >>> 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 don't think so.
>
> > I vaguely remember that I tried to achieve this a long time ago...
>
> ISTR you had an archer branch for that and other Windows stuff.
Oh, no...
I completely forgot that :(
It's been a loooong time since I last worked on that :(
> >
> > Anyhow, the memory leak is gone at least!
I found another leak, down the same line,
solib_target_current_sos
calls target_read_stralloc
which as its name suggests allocates the result on the heap...
But that string was not freed in the current code...
This patch fixes that leak.
2012-12-14 Pierre Muller <muller@sourceware.org>
* solib-target.c (solib_target_current_sos): Remove 'const'
qualifier from type of library_document local variable to be
able to free it and avoid a memory leak.
Index: src/gdb/solib-target.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-target.c,v
retrieving revision 1.24
diff -u -p -r1.24 solib-target.c
--- src/gdb/solib-target.c 4 Jan 2012 08:17:11 -0000 1.24
+++ src/gdb/solib-target.c 14 Dec 2012 10:17:58 -0000
@@ -246,7 +246,7 @@ static struct so_list *
solib_target_current_sos (void)
{
struct so_list *new_solib, *start = NULL, *last = NULL;
- const char *library_document;
+ char *library_document;
VEC(lm_info_p) *library_list;
struct lm_info *info;
int ix;
@@ -261,7 +261,10 @@ solib_target_current_sos (void)
/* Parse the list. */
library_list = solib_target_parse_libraries (library_document);
if (library_list == NULL)
- return NULL;
+ {
+ xfree (library_document);
+ return NULL;
+ }
/* Build a struct so_list for each entry on the list. */
for (ix = 0; VEC_iterate (lm_info_p, library_list, ix, info); ix++)
@@ -291,6 +294,9 @@ solib_target_current_sos (void)
/* Free the library list, but not its members. */
VEC_free (lm_info_p, library_list);
+ /* Also free allocated library_document string. */
+ xfree (library_document);
+
return start;
}