Re: [PATCH 4/5] perf symbol: Shrink the demangled Rust buffer to fit

From: Namhyung Kim

Date: Tue Oct 06 2026 - 16:07:28 EST


On Mon, Sep 28, 2026 at 02:02:26AM +0100, Michal Pluta wrote:
> The buffer a demangled Rust name is returned in is sized to whatever
> attempt succeeded, which is usually larger than the string it holds.
> Shrink it to the string's exact length before returning it.

Oh, you already have the patch! :)

Thanks,
Namhyung

>
> Signed-off-by: Michal Pluta <michalpl2003@xxxxxxxxx>
> ---
> tools/perf/util/symbol.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 1a52bc2980a0..858a14a91f79 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -2772,8 +2772,10 @@ char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
> break;
> demangled = tmp;
> if (rust_demangle_display_demangle(&rust_demangle, demangled, buf_len,
> - /*alternate=*/true) == OverflowOk)
> - return demangled;
> + /*alternate=*/true) == OverflowOk) {
> + tmp = realloc(demangled, strlen(demangled) + 1);
> + return tmp ?: demangled;
> + }
> }
> /* Failure to grow output buffer or buffer exceeded sensible bounds. */
> free(demangled);
> --
> 2.43.0
>