From aa18964dd64511305de0711fed912054da6f5d18 Mon Sep 17 00:00:00 2001 From: Triet Hoang Date: Tue, 18 Aug 2026 14:48:37 +0000 Subject: [PATCH] perf unwind: Handle allocation failure in libdw__get_entries() Check the return value of zalloc() before dereferencing the allocated dwfl_ui_ti structure. Return -ENOMEM when the allocation fails to avoid a NULL pointer dereference. Signed-off-by: Triet Hoang Acked-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/unwind-libdw.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 63a5c2253174..8d9fa6fd81c3 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -397,6 +397,11 @@ int libdw__get_entries(unwind_entry_cb_t cb, void *arg, dwfl = dwfl_ui_ti->dwfl; } else { dwfl_ui_ti = zalloc(sizeof(*dwfl_ui_ti)); + if (!dwfl_ui_ti) { + free(ui); + return -ENOMEM; + } + dwfl = dwfl_begin(&offline_callbacks); if (!dwfl) goto out;