linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing/histogram: fix a potential memory leak for kstrdup()
@ 2022-01-25  4:07 xkernel.wang
  2022-01-25 14:32 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-01-25  4:07 UTC (permalink / raw)
  To: rostedt, mingo; +Cc: linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

kfree() is missing on an error path to free the memory allocated by
kstrdup():
> p = param = kstrdup(data->params[i], GFP_KERNEL);
So it is better to free it via kfree(p).

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 kernel/trace/trace_events_hist.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index f01e442..1fac14c 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -3578,6 +3578,7 @@ static int trace_action_create(struct hist_trigger_data *hist_data,
 
 			var_ref_idx = find_var_ref_idx(hist_data, var_ref);
 			if (WARN_ON(var_ref_idx < 0)) {
+				kfree(p);
 				ret = var_ref_idx;
 				goto err;
 			}
-- 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tracing/histogram: fix a potential memory leak for kstrdup()
  2022-01-25  4:07 [PATCH] tracing/histogram: fix a potential memory leak for kstrdup() xkernel.wang
@ 2022-01-25 14:32 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2022-01-25 14:32 UTC (permalink / raw)
  To: xkernel.wang; +Cc: mingo, linux-kernel

On Tue, 25 Jan 2022 12:07:15 +0800
xkernel.wang@foxmail.com wrote:

> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> kfree() is missing on an error path to free the memory allocated by
> kstrdup():
> > p = param = kstrdup(data->params[i], GFP_KERNEL);  
> So it is better to free it via kfree(p).
> 

Applied. Thanks,

-- Steve

> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
>  kernel/trace/trace_events_hist.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index f01e442..1fac14c 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -3578,6 +3578,7 @@ static int trace_action_create(struct hist_trigger_data *hist_data,
>  
>  			var_ref_idx = find_var_ref_idx(hist_data, var_ref);
>  			if (WARN_ON(var_ref_idx < 0)) {
> +				kfree(p);
>  				ret = var_ref_idx;
>  				goto err;
>  			}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-25 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25  4:07 [PATCH] tracing/histogram: fix a potential memory leak for kstrdup() xkernel.wang
2022-01-25 14:32 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).