diff mbox series

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

Message ID 20240605134054.2626953-33-jmarchan@redhat.com (mailing list archive)
State New
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
Free hook in the error path.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 lib/trace-cmd/trace-hooks.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Steven Rostedt July 18, 2024, 1:16 a.m. UTC | #1
On Wed,  5 Jun 2024 15:40:47 +0200
"Jerome Marchand" <jmarchan@redhat.com> wrote:

> Free hook in the error path.
> 
> Fixes a RESOURCE_LEAK error (CWE-772)
> 
> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
> ---
>  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?

-- Steve

> +	free(hook);
>  	return NULL;
>  }
>
diff mbox series

Patch

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);
+	free(hook);
 	return NULL;
 }