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>
This commit is contained in:
Wang Nan 2015-09-14 10:23:55 +00:00 committed by Arnaldo Carvalho de Melo
parent 91a4dc9f71
commit bd315aab8a

View file

@ -1968,7 +1968,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
&options[nr_options], dso);
nr_options += add_map_opt(browser, &actions[nr_options],
&options[nr_options],
browser->selection->map);
browser->selection ?
browser->selection->map : NULL);
/* perf script support */
if (browser->he_selection) {
@ -1976,6 +1977,15 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
&actions[nr_options],
&options[nr_options],
thread, NULL);
/*
* Note that browser->selection != NULL
* when browser->he_selection is not NULL,
* so we don't need to check browser->selection
* before fetching browser->selection->sym like what
* we do before fetching browser->selection->map.
*
* See hist_browser__show_entry.
*/
nr_options += add_script_opt(browser,
&actions[nr_options],
&options[nr_options],