Re: [PATCH 32/38] trace-cmd lib: prevent memory leak in tracecmd_create_event_hook()

Jerome Marchand <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
On 18/07/2024 03:16, Steven Rostedt wrote:
> On Wed,  5 Jun 2024 15:40:47 +0200
> "Jerome Marchand" <[email protected]> wrote:
> 
>> Free hook in the error path.
>>
>> Fixes a RESOURCE_LEAK error (CWE-772)
>>
>> Signed-off-by: Jerome Marchand <[email protected]>
>> ---
>>   lib/trace-cmd/trace-hooks.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/trace-cmd/trace-hooks.c b/lib/trace-cmd/trace-hooks.c
>> index a58b5356..47f25fb3 100644
>> --- a/lib/trace-cmd/trace-hooks.c
>> +++ b/lib/trace-cmd/trace-hooks.c
>> @@ -151,6 +151,7 @@ struct hook_list *tracecmd_create_event_hook(const char *arg)
>>   
>>   invalid_tok:
>>   	tracecmd_warning("Invalid hook format '%s'", arg);
> 
> Should we also have:
> 
> 	free(hook->str);
> 
> here too?

Yes indeed. This wasn't detected by the static analyzer. I'll send an 
updated patch.

Jerome

> 
> -- Steve
> 
>> +	free(hook);
>>   	return NULL;
>>   }
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.