Re: [PATCH] perf unwind: handle allocation failure in libdw__get_entries()
| Newsgroups | org.kernel.vger.linux-perf-users |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Memory leak of `ui` structure upon `dwfl_ui_ti` allocation failure. -- --- Patch [1]: [PATCH] perf unwind: handle allocation failure in libdw__get_entries() --- commit cfa13e49d271d0f1a99af3ba9b78fd579579b1d0 Author: Triet Hoang <[email protected]> perf unwind: handle allocation failure in libdw__get_entries() This commit adds a return value check for zalloc() when allocating the dwfl_ui_ti structure. It returns -ENOMEM upon failure to avoid a NULL pointer dereference. > diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c > index 7f35042be5677..ff36552ca1759 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; [Severity: Medium] Does this code leak the previously allocated ui structure? Earlier in libdw__get_entries(), ui is allocated with: ui = zalloc(sizeof(*ui) + sizeof(ui->entries[0]) * max_stack); Returning directly here bypasses the cleanup path at the out label, which normally calls free(ui). Should we free the ui structure before returning -ENOMEM? > + > dwfl = dwfl_begin(&offline_callbacks); > if (!dwfl) > goto out; -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1