Skip to content

Commit 99d86c8

Browse files
olsajiriacmel
authored andcommitted
perf ordered_events: Fix crash in ordered_events__free
Song Liu reported crash in 'perf record': > #0 0x0000000000500055 in ordered_events(float, long double,...)(...) () > #1 0x0000000000500196 in ordered_events.reinit () > #2 0x00000000004fe413 in perf_session.process_events () > #3 0x0000000000440431 in cmd_record () > #4 0x00000000004a439f in run_builtin () > #5 0x000000000042b3e5 in main ()" This can happen when we get out of buffers during event processing. The subsequent ordered_events__free() call assumes oe->buffer != NULL and crashes. Add a check to prevent that. Reported-by: Song Liu <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Reviewed-by: Song Liu <[email protected]> Tested-by: Song Liu <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Fixes: d5ceb62 ("perf ordered_events: Add 'struct ordered_events_buffer' layer") Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4e72ee8 commit 99d86c8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/perf/util/ordered-events.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,10 @@ void ordered_events__free(struct ordered_events *oe)
391391
* Current buffer might not have all the events allocated
392392
* yet, we need to free only allocated ones ...
393393
*/
394-
list_del(&oe->buffer->list);
395-
ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
394+
if (oe->buffer) {
395+
list_del(&oe->buffer->list);
396+
ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
397+
}
396398

397399
/* ... and continue with the rest */
398400
list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) {

0 commit comments

Comments
 (0)