[PATCH 3/3] readelf.c: Close dwfl if dwfl_report_offline fails

Mark Wielaard mark@klomp.org
Mon Sep 8 21:21:58 GMT 2025


Hi Aaron,

On Sun, Sep 07, 2025 at 10:17:29PM -0400, Aaron Merey wrote:
> Within create_dwfl, if dwfl_begin is successful but dwfl_report_offline
> fails, the dwfl * pointer being reported is reset to NULL without calling
> dwfl_end, causing a memory leak.
> 
> Update create_dwfl to call dwfl_end in this case, preventing the leak.
> 
> Signed-off-by: Aaron Merey <amerey@redhat.com>
> ---
>  src/readelf.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/readelf.c b/src/readelf.c
> index 6b886c59..138ded6b 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -978,6 +978,7 @@ create_dwfl (int fd, const char *fname)
>  	error (0, 0, _("failed reading '%s': %s"),
>  	       fname, dwfl_errmsg (-1));
>        close (dwfl_fd);		/* Consumed on success, not on failure.  */
> +      dwfl_end (dwfl);
>        dwfl = NULL;
>      }
>    else

This looks obviously correct to me.

Thanks,

Mark


More information about the Elfutils-devel mailing list