Skip to content

Commit 4584f08

Browse files
captain5050acmel
authored andcommitted
perf parse: Fix potential memory leak when handling tracepoint errors
An error may be in place when tracepoint_error is called, use parse_events__handle_error to avoid a memory leak and to capture the first and last error. Error detected by LLVM's libFuzzer using the following event: $ perf stat -e 'msr/event/,f:e' event syntax error: 'msr/event/,f:e' \___ can't access trace events Error: No permissions to read /sys/kernel/debug/tracing/events/f/e Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing/' Initial error: event syntax error: 'msr/event/,f:e' \___ no value assigned for term Run 'perf list' for a list of valid events Usage: perf stat [<options>] [<command>] -e, --event <event> event selector. use 'perf list' to list available events Signed-off-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 358f98e commit 4584f08

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/perf/util/parse-events.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
511511
static void tracepoint_error(struct parse_events_error *e, int err,
512512
const char *sys, const char *name)
513513
{
514+
const char *str;
514515
char help[BUFSIZ];
515516

516517
if (!e)
@@ -524,18 +525,18 @@ static void tracepoint_error(struct parse_events_error *e, int err,
524525

525526
switch (err) {
526527
case EACCES:
527-
e->str = strdup("can't access trace events");
528+
str = "can't access trace events";
528529
break;
529530
case ENOENT:
530-
e->str = strdup("unknown tracepoint");
531+
str = "unknown tracepoint";
531532
break;
532533
default:
533-
e->str = strdup("failed to add tracepoint");
534+
str = "failed to add tracepoint";
534535
break;
535536
}
536537

537538
tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
538-
e->help = strdup(help);
539+
parse_events__handle_error(e, 0, strdup(str), strdup(help));
539540
}
540541

541542
static int add_tracepoint(struct list_head *list, int *idx,

0 commit comments

Comments
 (0)