Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Fix other memory leak in solib_target_current_sos
Date: Fri, 14 Dec 2012 10:55:00 -0000	[thread overview]
Message-ID: <50CB0574.7040406@redhat.com> (raw)
In-Reply-To: <000001cdd9e5$6868f6e0$393ae4a0$@muller@ics-cnrs.unistra.fr>

On 12/14/2012 10:25 AM, Pierre Muller wrote:

>   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.

Thanks.

> 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;
>  }
> 

Parsing XML, within solib_target_parse_libraries, may throw.  Thus, a
cleanup would be better:

+  old_chain = make_cleanup (xfree, library_document);
  library_list = solib_target_parse_libraries (library_document);
+  do_cleanups (old_chain);

-- 
Pedro Alves


  reply	other threads:[~2012-12-14 10:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-13 20:16 ` [RFA] Fix memory leak in windows_xfer_shared_libraries Pedro Alves
2012-12-14  7:53   ` Pierre Muller
2012-12-14 10:12     ` Pedro Alves
2012-12-14 10:26       ` [RFA] Fix other memory leak in solib_target_current_sos Pierre Muller
2012-12-14 10:55         ` Pedro Alves [this message]
2012-12-14 13:07           ` [RFA-v2] " Pierre Muller
2012-12-14 13:49             ` Pedro Alves
     [not found]       ` <43198.6185875305$1355480794@news.gmane.org>
2012-12-14 14:14         ` [RFA] " Tom Tromey
2012-12-14 23:29           ` Pierre Muller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50CB0574.7040406@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pierre.muller@ics-cnrs.unistra.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox