Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Michael Snyder <msnyder@vmware.com>
Subject: Re: [RFA] completer.c (expression_completer): Stop memory leak.
Date: Wed, 09 Mar 2011 20:29:00 -0000	[thread overview]
Message-ID: <201103092007.33388.pedro@codesourcery.com> (raw)
In-Reply-To: <4D77CDD6.7010700@vmware.com>

On Wednesday 09 March 2011 18:58:30, Michael Snyder wrote:
> In this case, it is possible for fieldname to be allocated before an 
> exception is thrown.
> 
> OK?

Notice how `fieldname' is uninitialized by expression_completer.
If an exception is thrown from within parse_field_expression
before writting to `fieldname', you'll be calling `free'
(it should be xfree, btw) on an uninitialized pointer.  That's
bad.

Please fix this within parse_field_expression itself.
1) even if what I describe above can't happen as is
today (it may or not, dunno), your change makes the
code quite fragile.  2) any other parse_field_expression call
that isn't wrapped in a TRY_CATCH like this, is a
potential leak.

-- 
Pedro Alves

> 
> completer.txt
>   2011-03-09  Michael Snyder  <msnyder@msnyder-server.eng.vmware.com>
> 
>         * completer.c (expression_completer): Stop memory leak.
> 
> Index: completer.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/completer.c,v
> retrieving revision 1.44
> diff -u -p -r1.44 completer.c
> --- completer.c 26 Feb 2011 02:07:07 -0000      1.44
> +++ completer.c 9 Mar 2011 18:56:24 -0000
> @@ -455,7 +455,10 @@ expression_completer (struct cmd_list_el
>        type = parse_field_expression (text, &fieldname);
>      }
>    if (except.reason < 0)
> -    return NULL;
> +    {
> +      free (fieldname);
> +      return NULL;


  reply	other threads:[~2011-03-09 20:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 20:07 Michael Snyder
2011-03-09 20:29 ` Pedro Alves [this message]
2011-03-09 23:58   ` Michael Snyder
2011-03-10  0:14     ` Pedro Alves

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=201103092007.33388.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=msnyder@vmware.com \
    /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