Skip to contentSkip to conversation

perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command()

PATCH In review Arnaldo Carvalho de Melo 3 participants 3 messages Aug 4, 2023 – Aug 11, 2023 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

PATCH 1/1 perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command()

Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected elsewhere and lead to an audit, where we found that synthesize_perf_probe_command() may leak synthesize_perf_probe_point() return on failure, fix it.

---
 tools/perf/util/probe-event.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +6 -2
index c7bfeab610a3679a..2835d87cb97771f9 100644
@@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
 			goto out;
 
 	tmp = synthesize_perf_probe_point(&pev->point);
-	if (!tmp || strbuf_addstr(&buf, tmp) < 0)
+	if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
+		free(tmp);
 		goto out;
+	}
 	free(tmp);
 
 	for (i = 0; i < pev->nargs; i++) {
 		tmp = synthesize_perf_probe_arg(pev->args + i);
-		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
+		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
+			free(tmp);
 			goto out;
+		}
 		free(tmp);
 	}
 
Signature · 1 line
2.37.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Arnaldo Carvalho de Melo

Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected elsewhere and lead to an audit, where we found that synthesize_perf_probe_command() may leak synthesize_perf_probe_point() return on failure, fix it.

Quoted 7 lines

Thanks,
Ian

Quoted 32 lines
---
 tools/perf/util/probe-event.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +6 -3
index c7bfeab610a3679a..2835d87cb97771f9 100644
@@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
                        goto out;
 
        tmp = synthesize_perf_probe_point(&pev->point);
-       if (!tmp || strbuf_addstr(&buf, tmp) < 0)
+       if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
+               free(tmp);
                goto out;
+       }
        free(tmp);
 
        for (i = 0; i < pev->nargs; i++) {
                tmp = synthesize_perf_probe_arg(pev->args + i);
-               if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
+               if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
+                       free(tmp);
                        goto out;
+               }
                free(tmp);
        }
 
--

2.37.1

Acked-by on v1 1/1
#2 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 4 lines · On Fri, 4 Aug 2023 13:26:54 -0300 Arnaldo Carvalho de Melo <[email protected]>…

Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected elsewhere and lead to an audit, where we found that synthesize_perf_probe_command() may leak synthesize_perf_probe_point() return on failure, fix it.

This looks good to me.

Thanks,

Quoted 40 lines
---
 tools/perf/util/probe-event.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +6 -2
index c7bfeab610a3679a..2835d87cb97771f9 100644
@@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
 			goto out;
 
 	tmp = synthesize_perf_probe_point(&pev->point);
-	if (!tmp || strbuf_addstr(&buf, tmp) < 0)
+	if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
+		free(tmp);
 		goto out;
+	}
 	free(tmp);
 
 	for (i = 0; i < pev->nargs; i++) {
 		tmp = synthesize_perf_probe_arg(pev->args + i);
-		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
+		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
+			free(tmp);
 			goto out;
+		}
 		free(tmp);
 	}
 
Signature · 1 line
2.37.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>