Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Triet Hoang" <triet.hoang.dev@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf unwind: handle allocation failure in libdw__get_entries()
Date: Tue, 18 Aug 2026 14:29:01 +0000	[thread overview]
Message-ID: <20260818142902.639F51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818142400.729633-1-triet.hoang.dev@gmail.com>

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 <triet.hoang.dev@gmail.com>

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/20260818142400.729633-1-triet.hoang.dev@gmail.com?part=1

  reply	other threads:[~2026-08-18 14:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 14:24 [PATCH] perf unwind: handle allocation failure in libdw__get_entries() Triet Hoang
2026-08-18 14:29 ` sashiko-bot [this message]
2026-08-18 14:48   ` [PATCH v2] " Triet Hoang
2026-08-18 14:59     ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260818142902.639F51F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=triet.hoang.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox