This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] completer.c (expression_completer): Stop memory leak.


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]