• Ben Gainey's avatar
    perf db-export: Fix missing reference count get in call_path_from_sample() · 1e24ce40
    Ben Gainey authored
    The addr_location map and maps fields in the inner loop were missing
    calls to map__get()/maps__get(). The subsequent addr_location__exit()
    call in each loop puts the map/maps fields causing use-after-free
    aborts.
    
    This issue reproduces on at least arm64 and x86_64 with something
    simple like `perf record -g ls` followed by `perf script -s script.py`
    with the following script:
    
        perf_db_export_mode = True
        perf_db_export_calls = False
        perf_db_export_callchains = True
    
        def sample_table(*args):
            print(f'sample_table({args})')
    
        def call_path_table(*args):
            print(f'call_path_table({args}')
    
    Committer testing:
    
    This test, just introduced by Ian Rogers, now passes, not segfaulting
    anymore:
    
      # perf test "perf script tests"
       95: perf script tests                                               : Ok
      #
    
    Fixes: 0dd5041c ("perf addr_location: Add init/exit/copy functions")
    Signed-off-by: default avatarBen Gainey <ben.gainey@arm.com>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Tested-by: default avatarIan Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.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/20231207140911.3240408-1-ben.gainey@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    1e24ce40
db-export.c 14.7 KB