Skip to content

Commit d61cbb8

Browse files
stkidacmel
authored andcommitted
perf report TUI: Fix segmentation fault in perf_evsel__hists_browse()
The segmentation fault can be reproduced as following steps: 1) Executing perf report in tui. 2) Typing '/xxxxx' to filter the symbol to get nothing matched. 3) Pressing enter with no entry selected. Then it will report a segmentation fault. It is caused by the lack of check of browser->he_selection when accessing it's member res_samples in perf_evsel__hists_browse(). These processes are meaningful for specified samples, so we can skip these when nothing is selected. Fixes: 4968ac8 ("perf report: Implement browsing of individual samples") Signed-off-by: Wei Li <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Hanjun Guo <[email protected]> Cc: Jin Yao <[email protected]> Cc: Mark Rutland <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 2160d6c commit d61cbb8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser
22882288
return browser->he_selection->thread;
22892289
}
22902290

2291+
static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser)
2292+
{
2293+
return browser->he_selection ? browser->he_selection->res_samples : NULL;
2294+
}
2295+
22912296
/* Check whether the browser is for 'top' or 'report' */
22922297
static inline bool is_report_browser(void *timer)
22932298
{
@@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
33573362
&options[nr_options], NULL, NULL, evsel);
33583363
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33593364
&options[nr_options],
3360-
hist_browser__selected_entry(browser)->res_samples,
3361-
evsel, A_NORMAL);
3365+
hist_browser__selected_res_sample(browser),
3366+
evsel, A_NORMAL);
33623367
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33633368
&options[nr_options],
3364-
hist_browser__selected_entry(browser)->res_samples,
3365-
evsel, A_ASM);
3369+
hist_browser__selected_res_sample(browser),
3370+
evsel, A_ASM);
33663371
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33673372
&options[nr_options],
3368-
hist_browser__selected_entry(browser)->res_samples,
3369-
evsel, A_SOURCE);
3373+
hist_browser__selected_res_sample(browser),
3374+
evsel, A_SOURCE);
33703375
nr_options += add_switch_opt(browser, &actions[nr_options],
33713376
&options[nr_options]);
33723377
skip_scripting:

0 commit comments

Comments
 (0)