Skip to contentSkip to conversation

libtracecmd: Return NULL if page is NULL in peek_last_event()

PATCH New Steven Rostedt 1 participant 1 message Jan 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracecmd: Return NULL if page is NULL in peek_last_event()

From: "Steven Rostedt (Google)" <[email protected]>

If the handle->cpu_data[cpu].page has been freed and cleared, consider the last event to be empty. This can happen if the buffer size is zero.

(Should we add a warning if page is NULL and size is not zero?)

---
 lib/trace-cmd/trace-input.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/trace-cmd/trace-input.c +4 -0
index f458dcec68a8..a10d74cf6cf4 100644
@@ -2973,6 +2973,10 @@ static struct tep_record *peek_last_event(struct tracecmd_input *handle,
 	if (record)
 		return record;
 
+	/* page can be NULL if the size is zero */
+	if (!page)
+		return NULL;
+
 	page_offset = page->offset - handle->page_size;
 	if (page_offset < handle->cpu_data[cpu].file_offset)
 		return NULL;
Signature · 1 line
2.43.0