Re: [PATCH v2] xfs: fix memory leak on error in xfs_alloc_zone_info()

From: Darrick J. Wong

Date: Tue Apr 14 2026 - 20:03:28 EST


On Wed, Apr 15, 2026 at 09:45:14AM +1000, Wilfred Mallawa wrote:
> From: Wilfred Mallawa <wilfred.mallawa@xxxxxxx>
>
> Currently, the 0th index of the zi_used_bucket_bitmap array is not freed
> on error due to the pre-decrement then evaluate semantic of the while
> loop used in xfs_alloc_zone_info(). Fix it by allowing for the i == 0
> case to be covered.
>
> Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
> Cc: stable@xxxxxxxxxxxxxxx

Cc: <stable@xxxxxxxxxxxxxxx> # v6.15

(autobackport plz, I need all the help I can get)

> Reviewed-by: Damien Le Moal <dlemoal@xxxxxxxxxx>
> Reviewed-by: Carlos Maiolino <cmaiolino@xxxxxxxxxx>
> Signed-off-by: Wilfred Mallawa <wilfred.mallawa@xxxxxxx>
> ---
> fs/xfs/xfs_zone_alloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/xfs/xfs_zone_alloc.c b/fs/xfs/xfs_zone_alloc.c
> index a851b98143c0..c64f9ab743a6 100644
> --- a/fs/xfs/xfs_zone_alloc.c
> +++ b/fs/xfs/xfs_zone_alloc.c
> @@ -1217,7 +1217,7 @@ xfs_alloc_zone_info(
> return zi;
>
> out_free_bitmaps:
> - while (--i > 0)
> + while (--i >= 0)

With the git trailer amended,
Reviewed-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>

--D

> kvfree(zi->zi_used_bucket_bitmap[i]);
> kfree(zi);
> return NULL;
> --
> 2.53.0
>
>