tools/perf/util: Fix memory leak in trace-event-info.c
PATCH v2 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-info.c +5 -2
@@ -518,13 +518,15 @@ 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 ; + err =-1 ; + 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 ; + err =-1 ; + goto err_tdata; }/*
@@ -562,6 +564,7 @@ out: output_fd = fd; } +err_tdata:if (err) {free (tdata); tdata =NULL ;
--
1.7.10.4
Namhyung Kim
maintainerHi Felipe,
Quoted 16 lines · Felipe Pena
Fix for a memory leak on
tracing_data_get()function when returning NULL explicitlySigned-off-by Felipe Pena <[email protected]>--- tools/perf/util/trace-event-info.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/perf/util/trace-event-info.c +0
-1@@ -518,13 +518,15 @@ 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 ;
tools/perf/util/trace-event-info.c struct tracing_data *tracing_data_get(struct list_head *pattrs, · line 529
Quoted 10 lines
tools/perf/util/trace-event-info.c +4
-1+ err =-1 ; + 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 ; + err =-1 ; + goto err_tdata;
I'd rather initialize err to -1 at the beginning. And the malloc of tdata should also be handled like this.
Thanks,
Namhyung
Quoted 13 lines
tools/perf/util/trace-event-info.c +1
-1}/* @@ -562,6 +564,7 @@ out: output_fd = fd; } +err_tdata:if (err) {free (tdata); tdata =NULL ; --1.7.10.4