Skip to content

Commit dccfca9

Browse files
Manciukicacmel
authored andcommitted
perf test event_update: Fix memory leak of unit
ASan reports a memory leak while running: # perf test "49: Synthesize attr update" Caused by a string being duplicated but never freed. This patch adds the missing free(). Note that evsel->unit is not deallocated together with evsel since it is supposed to be a constant string. Signed-off-by: Riccardo Mancini <[email protected]> Fixes: a6e5281 ("perf tools: Add event_update event unit type") Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/1fbc8158663fb0d4d5392e36bae564f6ad60be3c.1626343282.git.rickyman7@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fc56f54 commit dccfca9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/perf/tests/event_update.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
8888
struct evsel *evsel;
8989
struct event_name tmp;
9090
struct evlist *evlist = evlist__new_default();
91+
char *unit = strdup("KRAVA");
9192

9293
TEST_ASSERT_VAL("failed to get evlist", evlist);
9394

@@ -98,7 +99,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
9899

99100
perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
100101

101-
evsel->unit = strdup("KRAVA");
102+
evsel->unit = unit;
102103

103104
TEST_ASSERT_VAL("failed to synthesize attr update unit",
104105
!perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
@@ -118,6 +119,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
118119
TEST_ASSERT_VAL("failed to synthesize attr update cpus",
119120
!perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
120121

122+
free(unit);
121123
evlist__delete(evlist);
122124
return 0;
123125
}

0 commit comments

Comments
 (0)