• Dmitry Safonov's avatar
    perf diff: Don't crash on freeing errno-session on the error path · ffc52b7a
    Dmitry Safonov authored
    __cmd_diff() sets result of perf_session__new() to d->session.
    
    In case of failure, it's errno and perf-diff may crash with:
    
      failed to open perf.data: Permission denied
      Failed to open perf.data
      Segmentation fault (core dumped)
    
    From the coredump:
    
    0  0x00005569a62b5955 in auxtrace__free (session=0xffffffffffffffff)
        at util/auxtrace.c:2681
    1  0x00005569a626b37d in perf_session__delete (session=0xffffffffffffffff)
        at util/session.c:295
    2  perf_session__delete (session=0xffffffffffffffff) at util/session.c:291
    3  0x00005569a618008a in __cmd_diff () at builtin-diff.c:1239
    4  cmd_diff (argc=<optimized out>, argv=<optimized out>) at builtin-diff.c:2011
    [..]
    
    Funny enough, it won't always crash. For me it crashes only if failed
    file is second in cmd-line: the reason is that cmd_diff() check files for
    branch-stacks [in check_file_brstack()] and if the first file doesn't
    have brstacks, it doesn't proceed to try open other files from c...
    ffc52b7a
builtin-diff.c 46 KB