Re: libiberty/cplus-dem.c, ada-demangle: plug memory leak.

Michael Snyder
2011-03-04T18:07:36Z

Tristan Gingold wrote:
> On Mar 3, 2011, at 10:59 PM, Michael Snyder wrote:
>
>> Jakub Jelinek wrote:
>>> On Thu, Mar 03, 2011 at 01:20:28PM -0800, Michael Snyder wrote:
>>>> 2011-03-03 Michael Snyder <msnyder@vmware.com>
>>>>
>>>> * libiberty/cplus-dem.c (ada_demangle): Stop memory leak.
>>>> Also fix a one line indent problem.
>>> No libiberty/ in libiberty/ChangeLog.
>>>> @@ -1129,10 +1129,11 @@ ada_demangle (const char *mangled, int o
>>>> unknown:
>>>> len0 = strlen (mangled);
>>>> + xfree (demangled);
>>>> demangled = XNEWVEC (char, len0 + 3);
>>> xfree isn't ever used in libiberty/*, use either free, or
>>> XDELETE/XDELETEVEC. In fact, it seems to be defined only in gdb,
>>> making cplus-dem.c dependent on gdb is obviously a wrong thing.
>> Thanks for the review.
>>
>> How's this?
>
>> + if (demangled != NULL)
>> + free (demangled);
>
> No need to check that demangled is not NULL.

Are you sure? There is a path to "goto unknown" from before the
call to the alloc function. It might actually be null. Some
versions of 'free' don't like that.