Skip to content

Commit

Permalink
perf metric: Release expr_parse_ctx after testing
Browse files Browse the repository at this point in the history
The test_generic_metric() missed to release entries in the pctx.  Asan
reported following leak (and more):

  Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f4c9396980e in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10780e)
    thesofproject#1 0x55f7e748cc14 in hashmap_grow (/home/namhyung/project/linux/tools/perf/perf+0x90cc14)
    thesofproject#2 0x55f7e748d497 in hashmap__insert (/home/namhyung/project/linux/tools/perf/perf+0x90d497)
    thesofproject#3 0x55f7e7341667 in hashmap__set /home/namhyung/project/linux/tools/perf/util/hashmap.h:111
    thesofproject#4 0x55f7e7341667 in expr__add_ref util/expr.c:120
    thesofproject#5 0x55f7e7292436 in prepare_metric util/stat-shadow.c:783
    thesofproject#6 0x55f7e729556d in test_generic_metric util/stat-shadow.c:858
    thesofproject#7 0x55f7e712390b in compute_single tests/parse-metric.c:128
    thesofproject#8 0x55f7e712390b in __compute_metric tests/parse-metric.c:180
    thesofproject#9 0x55f7e712446d in compute_metric tests/parse-metric.c:196
    thesofproject#10 0x55f7e712446d in test_dcache_l2 tests/parse-metric.c:295
    thesofproject#11 0x55f7e712446d in test__parse_metric tests/parse-metric.c:355
    thesofproject#12 0x55f7e70be09b in run_test tests/builtin-test.c:410
    thesofproject#13 0x55f7e70be09b in test_and_print tests/builtin-test.c:440
    thesofproject#14 0x55f7e70c101a in __cmd_test tests/builtin-test.c:661
    thesofproject#15 0x55f7e70c101a in cmd_test tests/builtin-test.c:807
    thesofproject#16 0x55f7e7126214 in run_builtin /home/namhyung/project/linux/tools/perf/perf.c:312
    thesofproject#17 0x55f7e6fc41a8 in handle_internal_command /home/namhyung/project/linux/tools/perf/perf.c:364
    thesofproject#18 0x55f7e6fc41a8 in run_argv /home/namhyung/project/linux/tools/perf/perf.c:408
    thesofproject#19 0x55f7e6fc41a8 in main /home/namhyung/project/linux/tools/perf/perf.c:538
    thesofproject#20 0x7f4c93492cc9 in __libc_start_main ../csu/libc-start.c:308

Fixes: 6d432c4 ("perf tools: Add test_generic_metric function")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200915031819.386559-8-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
namhyung authored and acmel committed Sep 15, 2020
1 parent f5a5657 commit 437822b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/perf/util/stat-shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,14 +853,16 @@ static void generic_metric(struct perf_stat_config *config,
double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st)
{
struct expr_parse_ctx pctx;
double ratio;
double ratio = 0.0;

if (prepare_metric(mexp->metric_events, mexp->metric_refs, &pctx, cpu, st) < 0)
return 0.;
goto out;

if (expr__parse(&ratio, &pctx, mexp->metric_expr, 1))
return 0.;
ratio = 0.0;

out:
expr__ctx_clear(&pctx);
return ratio;
}

Expand Down

0 comments on commit 437822b

Please sign in to comment.