diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 45be944..6a2f663 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -42,19 +42,30 @@ int dso__read_binary_type_filename(const struct dso *dso,
size_t len;
switch (type) {
- case DSO_BINARY_TYPE__DEBUGLINK: {
+ case DSO_BINARY_TYPE__DEBUGLINK:
+ {
char *debuglink;
-
- strncpy(filename, dso->long_name, size);
- debuglink = filename + dso->long_name_len;
- while (debuglink != filename && *debuglink != '/')
- debuglink--;
- if (*debuglink == '/')
- debuglink++;
- ret = filename__read_debuglink(dso->long_name, debuglink,
- size - (debuglink - filename));
- }
+ char *filename_copy;
+
+ filename_copy = malloc(PATH_MAX);
+ if (filename_copy) {
+ len = __symbol__join_symfs(filename, size,
+ dso->long_name);
+ strncpy(filename_copy, filename, PATH_MAX);
+ debuglink = filename + len;
+ while (debuglink != filename && *debuglink != '/')
+ debuglink--;
+ if (*debuglink == '/')
+ debuglink++;
+ ret = filename__read_debuglink(filename_copy, debuglink,
+ size - (debuglink -
+ filename));
+ free(filename_copy);
+ } else
+ ret = -1;
break;
+ }
+