* [PATCH] perf ftrace: Fix leak in parse_filter_event
@ 2026-08-03 7:50 Michail Tatas
2026-08-04 17:04 ` Namhyung Kim
0 siblings, 1 reply; 2+ messages in thread
From: Michail Tatas @ 2026-08-03 7:50 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark
Cc: linux-perf-users, linux-kernel
strsep() advances the pointer given to it. After the loop s is
either NULL (on success) or points mid buffer (early exit if malloc
fails) so the original buffer is never freed properly.
Fix by adding a tmp pointer for use by strsep and free the original
pointer
Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
tools/perf/builtin-ftrace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index f7126196b092..4f881a40c311 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -1607,14 +1607,15 @@ static int parse_filter_event(const struct option *opt, const char *str,
{
struct list_head *head = opt->value;
struct filter_entry *entry;
- char *s, *p;
+ char *s, *p, *tmp;
int ret = -ENOMEM;
s = strdup(str);
if (s == NULL)
return -ENOMEM;
- while ((p = strsep(&s, ",")) != NULL) {
+ tmp = s;
+ while ((p = strsep(&tmp, ",")) != NULL) {
entry = malloc(sizeof(*entry) + strlen(p) + 1);
if (entry == NULL)
goto out;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf ftrace: Fix leak in parse_filter_event
2026-08-03 7:50 [PATCH] perf ftrace: Fix leak in parse_filter_event Michail Tatas
@ 2026-08-04 17:04 ` Namhyung Kim
0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2026-08-04 17:04 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, james.clark, Michail Tatas
Cc: linux-perf-users, linux-kernel
On Mon, 03 Aug 2026 10:50:04 +0300, Michail Tatas wrote:
> strsep() advances the pointer given to it. After the loop s is
> either NULL (on success) or points mid buffer (early exit if malloc
> fails) so the original buffer is never freed properly.
> Fix by adding a tmp pointer for use by strsep and free the original
> pointer
>
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-04 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 7:50 [PATCH] perf ftrace: Fix leak in parse_filter_event Michail Tatas
2026-08-04 17:04 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox