Re: [PATCH] fix: possible memory leak in unxz()

From: Andrew Morton
Date: Mon Oct 07 2024 - 21:50:53 EST


On Sun, 6 Oct 2024 12:55:43 +0530 Vishnu Sanal T <t.v.s10123@xxxxxxxxx> wrote:

> Fixes possible memory leak in the function unxz() in
> lib/decompress_unxz.c forgets to free the pointer 'in', when
> the statement if (fill == NULL && flush == NULL) is true.
>
> ...
>
> --- a/lib/decompress_unxz.c
> +++ b/lib/decompress_unxz.c
> @@ -343,13 +343,13 @@ STATIC int INIT unxz(unsigned char *in, long in_size,
> }
> } while (ret == XZ_OK);
>
> - if (must_free_in)
> - free(in);
> -
> if (flush != NULL)
> free(b.out);
> }
>
> + if (must_free_in)
> + free(in);
> +
> if (in_used != NULL)
> *in_used += b.in_pos;
>

Looks correct.

must_free_in needn't exist - `in' is always non-NULL here. And
free(NULL) is OK anwyay.