From: Ingo Molnar <mingo@kernel.org>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, acme@redhat.com, mingo@elte.hu,
peterz@infradead.org, jolsa@redhat.com, bccheng@google.com,
dsahern@gmail.com
Subject: Re: [PATCH] perf tools: fix bug in usage of the basename() function
Date: Thu, 5 Dec 2013 09:59:12 +0100 [thread overview]
Message-ID: <20131205085912.GB13377@gmail.com> (raw)
In-Reply-To: <20131205015557.GA13397@quad>
* Stephane Eranian <eranian@google.com> wrote:
>
> The basename() implementation varies a lot between systems.
> The Linux man page says: "basename may modify the content of the path,
> so it may be desirable to pass a copy when calling the function".
> On some other systems, the returned address may come from an internal
> buffer which can be reused in subsequent calls, thus the results should
> also be copied.
>
> The dso__set_basename() function was not doing this causing problems
> on some systems with wrong library names being shown by perf report,
> such as on Android systems.
>
> This patch fixes the problem.
> Thanks to Ben Cheng for tracking down the problem.
>
> Patch relative to tip.git at commit 631d5ea.
>
> Reported-by: Ben Cheng <bccheng@google.com>
> Signed-off-by: Stephane Eranian <eranian@google.com>
> ---
Just three nits:
> tools/perf/util/dso.c | 29 ++++++++++++++++++++++++++++-
> 1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
> index af4c687c..d186ace 100644
> --- a/tools/perf/util/dso.c
> +++ b/tools/perf/util/dso.c
> @@ -404,7 +404,34 @@ void dso__set_short_name(struct dso *dso, const char *name)
>
> static void dso__set_basename(struct dso *dso)
> {
> - dso__set_short_name(dso, basename(dso->long_name));
> + char *lname, *base;
> +
> + /*
> + * basename may modify path buffer, so we must pass
> + * a copy.
s/basename may modify path buffer
/basename() may modify the path buffer
> + */
> + lname = strdup(dso->long_name);
> + if (!lname)
> + return;
> +
> + /*
> + * basename may return pointer to internal
> + * storage which is reused in subsequent calls
> + * so copy the result
> + */
s/basename may return pointer
/basename() may return a pointer
Makes for easier reading.
(Also please use consistent periods - the first comment has a period,
the second one doesn't. ':' works well too:)
> + base = strdup(basename(lname));
> +
> + free(lname);
> +
> + if (!base)
> + return;
> +
> + if (dso->sname_alloc)
> + free((char *)dso->short_name);
That cast is probably not needed.
> + else
> + dso->sname_alloc = 1;
> +
> + dso__set_short_name(dso, base);
> }
>
> int dso__name_len(const struct dso *dso)
Otherwise:
Acked-by: Ingo Molnar <mingo@kernel.org>
Thanks,
Ingo
next prev parent reply other threads:[~2013-12-05 8:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-05 1:55 [PATCH] perf tools: fix bug in usage of the basename() function Stephane Eranian
2013-12-05 8:59 ` Ingo Molnar [this message]
2013-12-05 18:19 ` Stephane Eranian
2013-12-10 12:34 ` Ingo Molnar
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=20131205085912.GB13377@gmail.com \
--to=mingo@kernel.org \
--cc=acme@redhat.com \
--cc=bccheng@google.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.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