Re: [RFA] Fix a memory leak in py-param.c

Simon Marchi
2018-06-21T01:39:55Z

On 2018-06-20 17:38, Tom Tromey wrote:
> Mark Wielaard pointed out this memory leak to me:
>
> ==17633== 775 bytes in 1 blocks are definitely lost in loss record
> 13,346 of 13,967
> ==17633== at 0x4C2DB6B: malloc (vg_replace_malloc.c:299)
> ==17633== by 0x6652B7: xmalloc (common-utils.c:45)
> ==17633== by 0xC4C889: xstrdup (xstrdup.c:34)
> ==17633== by 0x5A71FD: unicode_to_encoded_string(_object*, char
> const*) (py-utils.c:81)
> ==17633== by 0x5A73EB: python_string_to_host_string(_object*)
> (py-utils.c:158)
> ==17633== by 0x59CC6C: get_doc_string(_object*, _object*)
> (py-param.c:334)
> ==17633== by 0x59D2AA: parmpy_init(_object*, _object*,
> _object*) (py-param.c:728)
>
> The bug here is that parmpy_init is written as though
> add_setshow_generic takes ownership of its doc-string arguments.
> However, it does not. This patch fixes the bug in a straightforward
> way and also applies some missing constification to make the problem
> more apparent.
>
> Tested on x86-64 Fedora 26.

LGTM, thanks.

Simon