Re: [PATCH] modpost: release allocation when early return no suffix .o in read_symbols()

From: Nathan Chancellor

Date: Wed Jun 17 2026 - 00:22:47 EST


On Wed, 10 Jun 2026 12:25:50 +0700, Robertus Diawan Chris <robertusdchris@xxxxxxxxx> wrote:
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index abbcd3fc1394..8e231544f9f3 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1585,6 +1585,7 @@ static void read_symbols(const char *modname)
>
> if (!strends(modname, ".o")) {
> error("%s: filename must be suffixed with .o\n", modname);
> + parse_elf_finish(&info);
> return;
> }
>

Thanks for the patch! While this change appears to be correct, would
moving the strends() if block before the parse_elf() one resolve this as
well? I think I would prefer going that route because neither check
really depends on the other and we have to think less about unwinding
with the checks flipped. Furthermore, modpost is a relatively short
running host utility, so I don't really think it is worth optimizing for
resource leaks like this.

--
Cheers,
Nathan