tools/perf/util: Fix memory leak in trace-event-info.c
PATCH 1/1 tools/perf/util: Fix memory leak in trace-event-info.c
Fix for a memory leak on tracing_data_get() function when returning NULL explicitly
Signed-off-by Felipe Pena <[email protected]>
--- tools/perf/util/trace-event-info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-info.c +6 -2
@@ -518,13 +518,13 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs, "/tmp/perf-XXXXXX");if (!mkstemp (tdata->temp_file)) {pr_debug ("Can't make temp file" ); -return NULL ; + goto err_tdata; } temp_fd =open (tdata->temp_file,O_RDWR );if (temp_fd <0 ) {pr_debug ("Can't read '%s'" , tdata->temp_file); -return NULL ; + goto err_tdata; }/*
@@ -569,6 +569,10 @@ out:put_tracepoints_path (tps);return tdata; + +err_tdata: +free (tdata); +return NULL ; }int tracing_data_put (struct tracing_data *tdata)
--
1.7.10.4
Namhyung Kim
maintainerHi Felipe,
Quoted 1 line · Felipe Pena
Fix for a memory leak on
tracing_data_get()function when returning NULL explicitly
Thanks for fixing this bug. Please see comment below.
Quoted 27 lines
Signed-off-by Felipe Pena <[email protected]>--- tools/perf/util/trace-event-info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)tools/perf/util/trace-event-info.c +2
-2@@ -518,13 +518,13 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs, "/tmp/perf-XXXXXX");if (!mkstemp (tdata->temp_file)) {pr_debug ("Can't make temp file" ); -return NULL ; + goto err_tdata; } temp_fd =open (tdata->temp_file,O_RDWR );if (temp_fd <0 ) {pr_debug ("Can't read '%s'" , tdata->temp_file); -return NULL ; + goto err_tdata; }/*
tools/perf/util/trace-event-info.c out: · line 576
Quoted 8 lines
tools/perf/util/trace-event-info.c +4
-0@@ -569,6 +569,10 @@ out:put_tracepoints_path (tps);return tdata; + +err_tdata: +free (tdata); +return NULL ; }
It should call put_tracepoints_path() too in case of error. So I suggest that setting err to an appropriate code and goto if (err) block above put_tracepoints_path().
Thanks,
Namhyung