Skip to content

Commit 25626e1

Browse files
James-A-Clarkacmel
authored andcommitted
perf symbols: Fix ownership of string in dso__load_vmlinux()
The linked commit updated dso__load_vmlinux() to call dso__set_long_name() before loading the symbols. Loading the symbols may not succeed but dso__set_long_name() takes ownership of the string. The two callers of this function free the string themselves on failure cases, resulting in the following error: $ perf record -- ls $ perf report free(): double free detected in tcache 2 Fix it by always taking ownership of the string, even on failure. This means the string is either freed at the very first early exit condition, or later when the dso is deleted or the long name is replaced. Now no special return value is needed to signify that the caller needs to free the string. Fixes: e59fea4 ("perf symbols: Fix DSO kernel load and symbol process to correctly map DSO to its long_name, type and adjust_symbols") Reviewed-by: Ian Rogers <[email protected]> Signed-off-by: James Clark <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f30232b commit 25626e1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tools/perf/util/symbol.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,10 @@ int dso__load(struct dso *dso, struct map *map)
19781978
return ret;
19791979
}
19801980

1981+
/*
1982+
* Always takes ownership of vmlinux when vmlinux_allocated == true, even if
1983+
* it returns an error.
1984+
*/
19811985
int dso__load_vmlinux(struct dso *dso, struct map *map,
19821986
const char *vmlinux, bool vmlinux_allocated)
19831987
{
@@ -1996,8 +2000,11 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
19962000
else
19972001
symtab_type = DSO_BINARY_TYPE__VMLINUX;
19982002

1999-
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
2003+
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type)) {
2004+
if (vmlinux_allocated)
2005+
free((char *) vmlinux);
20002006
return -1;
2007+
}
20012008

20022009
/*
20032010
* dso__load_sym() may copy 'dso' which will result in the copies having
@@ -2040,7 +2047,6 @@ int dso__load_vmlinux_path(struct dso *dso, struct map *map)
20402047
err = dso__load_vmlinux(dso, map, filename, true);
20412048
if (err > 0)
20422049
goto out;
2043-
free(filename);
20442050
}
20452051
out:
20462052
return err;
@@ -2192,7 +2198,6 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)
21922198
err = dso__load_vmlinux(dso, map, filename, true);
21932199
if (err > 0)
21942200
return err;
2195-
free(filename);
21962201
}
21972202

21982203
if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {

0 commit comments

Comments
 (0)