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

From: Leo Yan
Date: Fri Dec 25 2020 - 01:04:18 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
tools/perf/util/probe-file.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

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:
--
2.17.1