diff mbox series

[v2,1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command()

Message ID 20201225052751.24513-2-leo.yan@linaro.org
State New
Headers show
Series [v2,1/3] perf probe: Fix memory leak in synthesize_sdt_probe_command() | expand

Commit Message

Leo Yan Dec. 25, 2020, 5:27 a.m. UTC
From: Arnaldo Carvalho de Melo <acme@redhat.com>


In synthesize_sdt_probe_command(), it gets argument array from
argv_split() but forgets to free it.  This patch calls argv_free() to
free the argument array to avoid memory leak.

Fixes: 3b1f8311f696 ("perf probe: Add sdt probes arguments into the uprobe cmd string")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Leo Yan <leo.yan@linaro.org>

Cc: stable@vger.kernel.org
---
 tools/perf/util/probe-file.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 064b63a6a3f3..bbecb449ea94 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -791,7 +791,7 @@  static char *synthesize_sdt_probe_command(struct sdt_note *note,
 					const char *sdtgrp)
 {
 	struct strbuf buf;
-	char *ret = NULL, **args;
+	char *ret = NULL;
 	int i, args_count, err;
 	unsigned long long ref_ctr_offset;
 
@@ -813,12 +813,19 @@  static char *synthesize_sdt_probe_command(struct sdt_note *note,
 		goto out;
 
 	if (note->args) {
-		args = argv_split(note->args, &args_count);
+		char **args = argv_split(note->args, &args_count);
+
+		if (args == NULL)
+			goto error;
 
 		for (i = 0; i < args_count; ++i) {
-			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
+			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
+				argv_free(args);
 				goto error;
+			}
 		}
+
+		argv_free(args);
 	}
 
 out: