Skip to contentSkip to conversation

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

PATCH In review Felipe Pena 2 participants 2 messages Oct 14, 2013 – Oct 15, 2013 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v3 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 |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/perf/util/trace-event-info.c +6 -4
index f3c9e55..83b3a67 100644
@@ -496,7 +496,7 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
 {
 	struct tracepoint_path *tps;
 	struct tracing_data *tdata;
-	int err;
+	int err = -1;
 
 	output_fd = fd;
 
@@ -506,7 +506,7 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
 
 	tdata = malloc(sizeof(*tdata));
 	if (!tdata)
-		return NULL;
+		goto err_tps;
 
 	tdata->temp = temp;
 	tdata->size = 0;
@@ -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;
 		}
 
 		/*
@@ -562,11 +562,13 @@ out:
 		output_fd = fd;
 	}
 
+err_tdata:
 	if (err) {
 		free(tdata);
 		tdata = NULL;
 	}
 
+err_tps:
 	put_tracepoints_path(tps);
 	return tdata;
 }

--
1.7.10.4