[PATCH] perf unwind: handle allocation failure in libdw__get_entries()
From: Triet Hoang
Date: Tue Aug 18 2026 - 10:28:09 EST
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 <triet.hoang.dev@xxxxxxxxx>
---
tools/perf/util/unwind-libdw.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 7f35042be567..ff36552ca175 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -379,6 +379,9 @@ 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)
+ return -ENOMEM;
+
dwfl = dwfl_begin(&offline_callbacks);
if (!dwfl)
goto out;
--
2.53.0