diff options
| author | Jiri Olsa <jolsa@redhat.com> | 2019-03-05 10:25:31 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-06 16:16:57 -0500 |
| commit | 2634958586368dcbf09c0d2a17dee02d1fc53e0d (patch) | |
| tree | eb771c6bf14c2853eb43a5aa936d3aa1121da4a6 /tools/perf | |
| parent | c57589106fd6d996dbf3757708baa4a3fb91850f (diff) | |
perf hist: Fix memory leak of srcline
We can't allocate he->srcline unconditionaly, only when new hist_entry
is created. Moving he->srcline allocation into hist_entry__init
function.
Original-patch-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Nageswara R Sastry <nasastry@in.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lkml.kernel.org/r/20190305152536.21035-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/util/hist.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 74e307d17c49..f9eb95bf3938 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
| @@ -419,6 +419,13 @@ static int hist_entry__init(struct hist_entry *he, | |||
| 419 | if (he->raw_data == NULL) | 419 | if (he->raw_data == NULL) |
| 420 | goto err_infos; | 420 | goto err_infos; |
| 421 | } | 421 | } |
| 422 | |||
| 423 | if (he->srcline) { | ||
| 424 | he->srcline = strdup(he->srcline); | ||
| 425 | if (he->srcline == NULL) | ||
| 426 | goto err_rawdata; | ||
| 427 | } | ||
| 428 | |||
| 422 | INIT_LIST_HEAD(&he->pairs.node); | 429 | INIT_LIST_HEAD(&he->pairs.node); |
| 423 | thread__get(he->thread); | 430 | thread__get(he->thread); |
| 424 | he->hroot_in = RB_ROOT_CACHED; | 431 | he->hroot_in = RB_ROOT_CACHED; |
| @@ -429,6 +436,9 @@ static int hist_entry__init(struct hist_entry *he, | |||
| 429 | 436 | ||
| 430 | return 0; | 437 | return 0; |
| 431 | 438 | ||
| 439 | err_rawdata: | ||
| 440 | free(he->raw_data); | ||
| 441 | |||
| 432 | err_infos: | 442 | err_infos: |
| 433 | if (he->branch_info) { | 443 | if (he->branch_info) { |
| 434 | map__put(he->branch_info->from.map); | 444 | map__put(he->branch_info->from.map); |
| @@ -605,7 +615,7 @@ __hists__add_entry(struct hists *hists, | |||
| 605 | .map = al->map, | 615 | .map = al->map, |
| 606 | .sym = al->sym, | 616 | .sym = al->sym, |
| 607 | }, | 617 | }, |
| 608 | .srcline = al->srcline ? strdup(al->srcline) : NULL, | 618 | .srcline = (char *) al->srcline, |
| 609 | .socket = al->socket, | 619 | .socket = al->socket, |
| 610 | .cpu = al->cpu, | 620 | .cpu = al->cpu, |
| 611 | .cpumode = al->cpumode, | 621 | .cpumode = al->cpumode, |
| @@ -962,7 +972,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, | |||
| 962 | .map = al->map, | 972 | .map = al->map, |
| 963 | .sym = al->sym, | 973 | .sym = al->sym, |
| 964 | }, | 974 | }, |
| 965 | .srcline = al->srcline ? strdup(al->srcline) : NULL, | 975 | .srcline = (char *) al->srcline, |
| 966 | .parent = iter->parent, | 976 | .parent = iter->parent, |
| 967 | .raw_data = sample->raw_data, | 977 | .raw_data = sample->raw_data, |
| 968 | .raw_size = sample->raw_size, | 978 | .raw_size = sample->raw_size, |
