aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2013-12-04 12:31:30 -0800
committerBen Cheng <bccheng@google.com>2013-12-04 12:31:30 -0800
commit89b9ec5b0b296bc6340d30a9ebf5016d28489bd8 (patch)
tree33708989063c4f743e2dab3176e5ebc70d4bcb44
parent7480fa0ee058c223e3da79473d048247b2aa8533 (diff)
downloadlinux-tools-perf-89b9ec5b0b296bc6340d30a9ebf5016d28489bd8.tar.gz
[PATCH] perf tool: fix bug in usage of the basename() function
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". The dso__set_basename() function was not doing this causing problems on some systems with wrong library names being shown by perf report. This patch fixes the problem. Change-Id: I1501adff2c092f7863f8673892bea93f2cb74563 Reported-by: Ben Cheng <bccheng@google.com> Signed-off-by: Stephane Eranian <eranian@google.com>
-rw-r--r--perf-3.12.0/tools/perf/util/dso.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/perf-3.12.0/tools/perf/util/dso.c b/perf-3.12.0/tools/perf/util/dso.c
index e3c1ff8..0e18da0 100644
--- a/perf-3.12.0/tools/perf/util/dso.c
+++ b/perf-3.12.0/tools/perf/util/dso.c
@@ -381,7 +381,38 @@ 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.
+ */
+ 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
+ */
+ base = strdup(basename(lname));
+
+ free(lname);
+
+ if (!base)
+ return;
+
+ if (dso->sname_alloc)
+ free((char *)dso->short_name);
+ else
+ dso->sname_alloc = 1;
+ /*
+ * basename may modify content, so we must pass
+ * a copy. Moreover basename may return pointer to internal
+ * storage we may be reusing later on
+ */
+ dso__set_short_name(dso, base);
}
int dso__name_len(const struct dso *dso)