On Fri, 10 Oct 2025 at 12:53, Alex Bennée <[email protected]> wrote:
>
> Peter Maydell <[email protected]> writes:
>
> > On Wed, 8 Oct 2025 at 20:17, Daan De Meyer <[email protected]> wrote:
> >> +    } else {
> >> +        fprintf(stderr,
> >> +                "unable to handle EFI zboot image with \"%.*s\" 
> >> compression\n",
> >> +                (int)sizeof(header->compression_type) - 1,
> >> +                header->compression_type);
> >> +        return -1;
> >
> > Moving the "unrecognized compression type" error path down to
> > here means that we have moved it below the g_malloc() of the
> > data buffer, so we now need to g_free() to avoid a leak.
>
> Could we not declare:
>
>       g_autofree uint8_t *data = NULL;
>
> and drop the cleanup?

You could, if you wanted to, convert the file to g_autofree, yes.
You would need to also adjust the tail end of the function
in the success path to do
  *buffer = g_realloc(g_steal_pointer(&data), bytes);
so we don't double-free (and drop the cleanup in other
error exit paths).

I don't mind either way, but if we want to convert to g_autofree
we should do it as a preliminary patch.

-- PMM

Reply via email to