Commit 4309bd9
perf script: Fix allocation of evsel->priv related to per-event dump files
[ Upstream commit 36d3e41 ]
When printing output we may want to generate per event files, where the
--per-event-dump option should be used, creating perf.data.EVENT.dump
files instead of printing to stdout.
The callback thar processes event thus expects that evsel->priv->fp
should point to either the per-event FILE descriptor or to stdout.
The a3af66f ("perf script: Fix crash because of missing
evsel->priv") changeset fixed a case where evsel->priv wasn't setup,
thus set to NULL, causing a segfault when trying to access
evsel->priv->fp.
But it did it for the non --per-event-dump case by allocating a 'struct
perf_evsel_script' just to set its ->fp to stdout.
Since evsel->priv is only freed when --per-event-dump is used, we ended
up with a memory leak, detected using ASAN.
Fix it by using the same method as perf_script__setup_per_event_dump(),
and reuse that static 'struct perf_evsel_script'.
Also check if evsel_script__new() failed.
Fixes: a3af66f ("perf script: Fix crash because of missing evsel->priv")
Reported-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: https://lore.kernel.org/lkml/ZH+F0wGAWV14zvMP@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 7cfd310 commit 4309bd9
1 file changed
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2390 | 2390 | | |
2391 | 2391 | | |
2392 | 2392 | | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
2393 | 2396 | | |
2394 | 2397 | | |
2395 | 2398 | | |
| |||
2398 | 2401 | | |
2399 | 2402 | | |
2400 | 2403 | | |
2401 | | - | |
2402 | 2404 | | |
2403 | 2405 | | |
2404 | 2406 | | |
| |||
2408 | 2410 | | |
2409 | 2411 | | |
2410 | 2412 | | |
2411 | | - | |
| 2413 | + | |
2412 | 2414 | | |
2413 | | - | |
2414 | | - | |
2415 | | - | |
| 2415 | + | |
2416 | 2416 | | |
2417 | | - | |
2418 | | - | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
2419 | 2420 | | |
2420 | 2421 | | |
2421 | 2422 | | |
| |||
2721 | 2722 | | |
2722 | 2723 | | |
2723 | 2724 | | |
2724 | | - | |
2725 | 2725 | | |
2726 | 2726 | | |
2727 | 2727 | | |
| |||
0 commit comments