• James Clark's avatar
    perf symbols: Fix ownership of string in dso__load_vmlinux() · 25626e19
    James Clark authored
    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: e59fea47 ("perf symbols: Fix DSO kernel load and symbol process to correctly map DSO to its long_name, type and adjust_symbols")
    Reviewed-by: default avatarIan Rogers <irogers@google.com>
    Signed-off-by: default avatarJames Clark <james.clark@arm.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20240507141210.195939-5-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    25626e19
symbol.c 60.5 KB