perf top: Fix segfault pressing -> with no hist entries
authorWang Nan <wangnan0@huawei.com>
Mon, 14 Sep 2015 10:23:55 +0000 (10:23 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 14 Sep 2015 18:10:41 +0000 (15:10 -0300)
commitbd315aab8a3ab1bc7074774b89a5d8ec7c1ff7ab
tree6bbfae36a5de2b02f6b0fabb6eb05fcb8aad4d5b
parent91a4dc9f71e4b8f9b8da547d19f80e7be89d7539
perf top: Fix segfault pressing -> with no hist entries

'perf top' segfaults with following operation:

 # perf top -e page-faults -p 11400 # 11400 never generates page-fault

Then on the resulting empty interface, press right key:

  # ./perf top -e page-faults -p 11400
  perf: Segmentation fault
  -------- backtrace --------
  ./perf[0x535428]
  /lib64/libc.so.6(+0x3545f)[0x7f0dd360745f]
  ./perf[0x531d46]
  ./perf(perf_evlist__tui_browse_hists+0x96)[0x5340d6]
  ./perf[0x44ba2f]
  /lib64/libpthread.so.0(+0x81d0)[0x7f0dd49dc1d0]
  /lib64/libc.so.6(clone+0x6c)[0x7f0dd36b90dc]

The bug resides in perf_evsel__hists_browse() that, in the above
circumstance browser->selection can be NULL, but code after
skip_annotation doesn't consider it.

This patch fix it by checking browser->selection before fetching
browser->selection->map.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1442226235-117265-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/hists.c