From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH 2/4] perf tools: Do the error path hist_entry release in hist_entry__new
Date: Mon, 4 Jul 2016 16:09:47 -0300 [thread overview]
Message-ID: <20160704190947.GW5324@kernel.org> (raw)
In-Reply-To: <1467640899-3776-3-git-send-email-jolsa@kernel.org>
Em Mon, Jul 04, 2016 at 04:01:37PM +0200, Jiri Olsa escreveu:
> It's better to release the hist_entry object in
> hist_entry__new function (where it's allocated)
> rather than in hist_entry__init.
Please combine this with the previous patch, that way this all gets
clearer :-\
- Arnaldo
> Link: http://lkml.kernel.org/n/tip-uoatzgsbdk3ebaeu56kdb9ku@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/util/hist.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index ed7bea9aa68d..04f3b52a319c 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -360,10 +360,8 @@ static int hist_entry__init(struct hist_entry *he,
>
> if (symbol_conf.cumulate_callchain) {
> he->stat_acc = malloc(sizeof(he->stat));
> - if (he->stat_acc == NULL) {
> - free(he);
> + if (he->stat_acc == NULL)
> return -ENOMEM;
> - }
> memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
> if (!sample_self)
> memset(&he->stat, 0, sizeof(he->stat));
> @@ -381,7 +379,6 @@ static int hist_entry__init(struct hist_entry *he,
> if (he->branch_info == NULL) {
> map__zput(he->ms.map);
> free(he->stat_acc);
> - free(he);
> return -ENOMEM;
> }
>
> @@ -415,7 +412,6 @@ static int hist_entry__init(struct hist_entry *he,
> map__put(he->mem_info->daddr.map);
> }
> free(he->stat_acc);
> - free(he);
> return -ENOMEM;
> }
> }
> @@ -439,10 +435,13 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
> callchain_size = sizeof(struct callchain_root);
>
> he = zalloc(sizeof(*he) + callchain_size);
> - if (he)
> + if (he) {
> err = hist_entry__init(he, template, sample_self);
> + if (err)
> + zfree(&he);
> + }
>
> - return err ? NULL : he;
> + return he;
> }
>
> static u8 symbol__parent_filter(const struct symbol *parent)
> --
> 2.4.11
next prev parent reply other threads:[~2016-07-04 19:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-04 14:01 [RFC 0/4] perf tools: Add hist_entry allocation callbacks Jiri Olsa
2016-07-04 14:01 ` [PATCH 1/4] perf tools: Introduce hist_entry__init function Jiri Olsa
2016-07-04 19:08 ` Arnaldo Carvalho de Melo
2016-07-04 14:01 ` [PATCH 2/4] perf tools: Do the error path hist_entry release in hist_entry__new Jiri Olsa
2016-07-04 19:09 ` Arnaldo Carvalho de Melo [this message]
2016-07-05 6:32 ` Jiri Olsa
2016-07-04 14:01 ` [PATCH 3/4] perf tools: Introduce hist_entry_ops Jiri Olsa
2016-07-04 14:01 ` [PATCH 4/4] perf tools: Introduce hists__add_entry_ops function 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=20160704190947.GW5324@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=dsahern@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox