[lkml]   [2019]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH AUTOSEL 5.4 335/350] perf parse: Fix potential memory leak when handling tracepoint errors
From: Ian Rogers <>

[ Upstream commit 4584f084aa9d8033d5911935837dbee7b082d0e9 ]

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 <>
Cc: Alexander Shishkin <>
Cc: Andi Kleen <>
Cc: Jin Yao <>
Cc: Jiri Olsa <>
Cc: Mark Rutland <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Stephane Eranian <>
Signed-off-by: Arnaldo Carvalho de Melo <>
Signed-off-by: Sasha Levin <>
tools/perf/util/parse-events.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 422ad1888e74f..9a958ec5a096d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -480,6 +480,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
static void tracepoint_error(struct parse_events_error *e, int err,
const char *sys, const char *name)
+ const char *str;
char help[BUFSIZ];

if (!e)
@@ -493,18 +494,18 @@ static void tracepoint_error(struct parse_events_error *e, int err,

switch (err) {
case EACCES:
- e->str = strdup("can't access trace events");
+ str = "can't access trace events";
case ENOENT:
- e->str = strdup("unknown tracepoint");
+ str = "unknown tracepoint";
- e->str = strdup("failed to add tracepoint");
+ str = "failed to add tracepoint";

tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
- e->help = strdup(help);
+ parse_events__handle_error(e, 0, strdup(str), strdup(help));

static int add_tracepoint(struct list_head *list, int *idx,
 \ /
  Last update: 2019-12-10 22:15    [W:1.920 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site