diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-03-05 10:25:30 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-06 16:16:30 -0500 |
commit | c57589106fd6d996dbf3757708baa4a3fb91850f (patch) | |
tree | 6322589c2e2318c2d7ae433a2ebcb9bb25f1e989 /tools | |
parent | e34c940245437f36d2c492edd1f8237eff391064 (diff) |
perf hist: Add error path into hist_entry__init
Adding error path into hist_entry__init to unify error handling, so
every new member does not need to free everything else.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: nageswara r sastry <nasastry@in.ibm.com>
Link: http://lkml.kernel.org/r/20190305152536.21035-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/hist.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 669f961316f0..74e307d17c49 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -396,11 +396,8 @@ static int hist_entry__init(struct hist_entry *he, | |||
396 | * adding new entries. So we need to save a copy. | 396 | * adding new entries. So we need to save a copy. |
397 | */ | 397 | */ |
398 | he->branch_info = malloc(sizeof(*he->branch_info)); | 398 | he->branch_info = malloc(sizeof(*he->branch_info)); |
399 | if (he->branch_info == NULL) { | 399 | if (he->branch_info == NULL) |
400 | map__zput(he->ms.map); | 400 | goto err; |
401 | free(he->stat_acc); | ||
402 | return -ENOMEM; | ||
403 | } | ||
404 | 401 | ||
405 | memcpy(he->branch_info, template->branch_info, | 402 | memcpy(he->branch_info, template->branch_info, |
406 | sizeof(*he->branch_info)); | 403 | sizeof(*he->branch_info)); |
@@ -419,21 +416,8 @@ static int hist_entry__init(struct hist_entry *he, | |||
419 | 416 | ||
420 | if (he->raw_data) { | 417 | if (he->raw_data) { |
421 | he->raw_data = memdup(he->raw_data, he->raw_size); | 418 | he->raw_data = memdup(he->raw_data, he->raw_size); |
422 | 419 | if (he->raw_data == NULL) | |
423 | if (he->raw_data == NULL) { | 420 | goto err_infos; |
424 | map__put(he->ms.map); | ||
425 | if (he->branch_info) { | ||
426 | map__put(he->branch_info->from.map); | ||
427 | map__put(he->branch_info->to.map); | ||
428 | free(he->branch_info); | ||
429 | } | ||
430 | if (he->mem_info) { | ||
431 | map__put(he->mem_info->iaddr.map); | ||
432 | map__put(he->mem_info->daddr.map); | ||
433 | } | ||
434 | free(he->stat_acc); | ||
435 | return -ENOMEM; | ||
436 | } | ||
437 | } | 421 | } |
438 | INIT_LIST_HEAD(&he->pairs.node); | 422 | INIT_LIST_HEAD(&he->pairs.node); |
439 | thread__get(he->thread); | 423 | thread__get(he->thread); |
@@ -444,6 +428,21 @@ static int hist_entry__init(struct hist_entry *he, | |||
444 | he->leaf = true; | 428 | he->leaf = true; |
445 | 429 | ||
446 | return 0; | 430 | return 0; |
431 | |||
432 | err_infos: | ||
433 | if (he->branch_info) { | ||
434 | map__put(he->branch_info->from.map); | ||
435 | map__put(he->branch_info->to.map); | ||
436 | free(he->branch_info); | ||
437 | } | ||
438 | if (he->mem_info) { | ||
439 | map__put(he->mem_info->iaddr.map); | ||
440 | map__put(he->mem_info->daddr.map); | ||
441 | } | ||
442 | err: | ||
443 | map__zput(he->ms.map); | ||
444 | free(he->stat_acc); | ||
445 | return -ENOMEM; | ||
447 | } | 446 | } |
448 | 447 | ||
449 | static void *hist_entry__zalloc(size_t size) | 448 | static void *hist_entry__zalloc(size_t size) |