Skip to contentSkip to conversation

tools/perf/util: Fix memory leak in trace-event-info.c

PATCH Superseded Felipe Pena 2 participants 2 messages Oct 10, 2013 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

---
 tools/perf/util/trace-event-info.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-info.c +6 -2
index f3c9e55..06f8624 100644
@@ -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

maintainer
#1 lore raw

Hi 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
---
 tools/perf/util/trace-event-info.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-info.c +2 -2
index f3c9e55..06f8624 100644
@@ -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