From: tip-bot for Jiri Olsa <tipbot@zytor.com> To: linux-tip-commits@vger.kernel.org Cc: namhyung@kernel.org, ravi.bangoria@linux.ibm.com, peterz@infradead.org, hpa@zytor.com, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, jonas.rabenstein@studium.uni-erlangen.de, ak@linux.intel.com, tglx@linutronix.de, mingo@kernel.org, acme@redhat.com, nasastry@in.ibm.com, jolsa@kernel.org Subject: [tip:perf/urgent] perf hist: Add error path into hist_entry__init Date: Sat, 9 Mar 2019 12:06:21 -0800 Message-ID: <tip-c57589106fd6d996dbf3757708baa4a3fb91850f@git.kernel.org> (raw) In-Reply-To: <20190305152536.21035-3-jolsa@kernel.org> Commit-ID: c57589106fd6d996dbf3757708baa4a3fb91850f Gitweb: https://git.kernel.org/tip/c57589106fd6d996dbf3757708baa4a3fb91850f Author: Jiri Olsa <jolsa@kernel.org> AuthorDate: Tue, 5 Mar 2019 16:25:30 +0100 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Wed, 6 Mar 2019 18:16:30 -0300 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> --- tools/perf/util/hist.c | 39 +++++++++++++++++++-------------------- 1 file 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, * adding new entries. So we need to save a copy. */ he->branch_info = malloc(sizeof(*he->branch_info)); - if (he->branch_info == NULL) { - map__zput(he->ms.map); - free(he->stat_acc); - return -ENOMEM; - } + if (he->branch_info == NULL) + goto err; memcpy(he->branch_info, template->branch_info, sizeof(*he->branch_info)); @@ -419,21 +416,8 @@ static int hist_entry__init(struct hist_entry *he, if (he->raw_data) { he->raw_data = memdup(he->raw_data, he->raw_size); - - if (he->raw_data == NULL) { - map__put(he->ms.map); - if (he->branch_info) { - map__put(he->branch_info->from.map); - map__put(he->branch_info->to.map); - free(he->branch_info); - } - if (he->mem_info) { - map__put(he->mem_info->iaddr.map); - map__put(he->mem_info->daddr.map); - } - free(he->stat_acc); - return -ENOMEM; - } + if (he->raw_data == NULL) + goto err_infos; } INIT_LIST_HEAD(&he->pairs.node); thread__get(he->thread); @@ -444,6 +428,21 @@ static int hist_entry__init(struct hist_entry *he, he->leaf = true; return 0; + +err_infos: + if (he->branch_info) { + map__put(he->branch_info->from.map); + map__put(he->branch_info->to.map); + free(he->branch_info); + } + if (he->mem_info) { + map__put(he->mem_info->iaddr.map); + map__put(he->mem_info->daddr.map); + } +err: + map__zput(he->ms.map); + free(he->stat_acc); + return -ENOMEM; } static void *hist_entry__zalloc(size_t size)
next prev parent reply index Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-05 15:25 [PATCH 0/8] perf tools: Assorted fixes Jiri Olsa 2019-03-05 15:25 ` [PATCH 1/8] perf c2c: Fix c2c report for empty numa node Jiri Olsa 2019-03-09 20:05 ` [tip:perf/urgent] " tip-bot for Jiri Olsa 2019-03-05 15:25 ` [PATCH 2/8] perf tools: Add error path into hist_entry__init Jiri Olsa 2019-03-09 20:06 ` tip-bot for Jiri Olsa [this message] 2019-03-05 15:25 ` [PATCH 3/8] perf hist: Fix memory leak of srcline Jiri Olsa 2019-03-09 20:07 ` [tip:perf/urgent] " tip-bot for Jiri Olsa 2019-03-05 15:25 ` [PATCH 4/8] perf tools: Read and store caps/max_precise in perf_pmu Jiri Olsa 2019-03-09 20:07 ` [tip:perf/urgent] " tip-bot for Jiri Olsa 2019-03-05 15:25 ` [PATCH 5/8] perf tools: Get precise_ip from the pmu config Jiri Olsa 2019-03-05 16:13 ` Andi Kleen 2019-03-05 16:28 ` Jiri Olsa 2019-03-05 16:40 ` Andi Kleen 2019-03-07 15:35 ` [PATCHv2 " Jiri Olsa 2019-03-07 16:51 ` Andi Kleen 2019-03-07 22:32 ` Jiri Olsa 2019-03-14 14:01 ` Jiri Olsa 2019-03-14 15:49 ` Andi Kleen 2019-03-15 12:15 ` [PATCH] perf tools: Move precise_ip detection into perf_evsel__open Jiri Olsa 2019-03-15 14:05 ` Andi Kleen 2019-03-15 14:35 ` Arnaldo Carvalho de Melo 2019-03-15 14:52 ` Jiri Olsa 2019-03-23 15:04 ` Jiri Olsa 2019-03-25 14:53 ` Arnaldo Carvalho de Melo 2019-03-05 15:25 ` [PATCH 6/8] perf tools: Probe for precise_ip with simple attr Jiri Olsa 2019-03-09 20:08 ` [tip:perf/urgent] perf evsel: " tip-bot for Jiri Olsa 2019-03-05 15:25 ` [PATCH 7/8] perf tools: Fix double free in perf_data__close Jiri Olsa 2019-03-09 20:09 ` [tip:perf/urgent] perf session: " tip-bot for Jiri Olsa 2019-03-05 15:25 ` [PATCH 8/8] perf tools: Force perf_data__open|close zero data->file.path Jiri Olsa 2019-03-09 20:09 ` [tip:perf/urgent] perf data: " tip-bot for Jiri Olsa
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tip-c57589106fd6d996dbf3757708baa4a3fb91850f@git.kernel.org \ --to=tipbot@zytor.com \ --cc=acme@redhat.com \ --cc=ak@linux.intel.com \ --cc=alexander.shishkin@linux.intel.com \ --cc=hpa@zytor.com \ --cc=jolsa@kernel.org \ --cc=jonas.rabenstein@studium.uni-erlangen.de \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-tip-commits@vger.kernel.org \ --cc=mingo@kernel.org \ --cc=namhyung@kernel.org \ --cc=nasastry@in.ibm.com \ --cc=peterz@infradead.org \ --cc=ravi.bangoria@linux.ibm.com \ --cc=tglx@linutronix.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
LKML Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \ linux-kernel@vger.kernel.org public-inbox-index lkml Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git