This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix memory leak in cp-support.c (cp_canonicalize_string)
- From: Pedro Alves <palves at redhat dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>, Alex Lindsay <alexlindsay239 at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 9 Aug 2017 13:09:10 +0100
- Subject: Re: [PATCH] Fix memory leak in cp-support.c (cp_canonicalize_string)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 79527C0C8B90
- References: <20170807201821.25207-1-alexlindsay239@gmail.com> <86k22dyno6.fsf@gmail.com>
On 08/09/2017 12:40 PM, Yao Qi wrote:
> Alex Lindsay <alexlindsay239@gmail.com> writes:
>
>> Formerly, in cp_canonicalize_string in cp-support.c, the return value of
>> cp_comp_to_string was never freed, creating a sizable memory leak detectable
>> with valgrind. This patch fixes the leak. However, a longer term solution
>> would be to change the return type of cp_comp_to_string to
>> gdb::unique_xmalloc_ptr<char>.
>
> Hi Alex,
> Thanks a lot for the investigation and the patch. I revise it a little
> to use gdb::unique_xmalloc_ptr<char>, and fix another leak somewhere else.
> Patch below is pushed in.
>
Sorry about that, and thanks for the fix.
I think I'd be good if cp_comp_to_string was changed to
return a unique_ptr itself, to avoid similar cases creeping
back in.
As penance, I'll give it a try.
Thanks,
Pedro Alves