[PATCH,V3 1/3] CTF: fix incorrect function return type

Wei-min Pan weimin.pan@oracle.com
Thu Apr 1 19:00:01 GMT 2021


On 4/1/2021 9:54 AM, Tom Tromey wrote:
>>>>>> Weimin Pan via Gdb-patches <gdb-patches@sourceware.org> writes:
>> +	Don't copy name returned from ctf_type_aname_raw throughout file.
> To be clear, this relies on the pointers from libctf having the correct
> lifetime.  If that's not the case, you'll get crashes.
>
>> -  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
>> +  char *name = ctf_type_aname_raw (fp, tid);
> Dropping the unique_xmalloc_ptr here makes me suspect that
> ctf_type_aname_raw is returning a malloc'd pointer.  So, this change
> would seem to leak memory.

Function ctf_type_aname_raw does strdup the type name. So it won't crash
but will cause mamory leaks as you suspected. Instead should have used
the combination of another libctf function ctf_type_name_raw which doesn't
strdup the name and unique_xmalloc_ptr.

Thank you very much for the comment.

>
> Tom


More information about the Gdb-patches mailing list