[PATCH] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()

Wilfred Mallawa posted 1 patch 2 months ago
fs/xfs/xfs_zone_gc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()
Posted by Wilfred Mallawa 2 months ago
From: Wilfred Mallawa <wilfred.mallawa@wdc.com>

In xfs_zone_gc_mount(), on error, a struct xfs_zone_gc_data allocated
with xfs_zone_gc_data_alloc() is freed with kfree(), however, this
doesn't free the underlying folios or the rmap_irecs.

Use xfs_zone_gc_data_free() to correctly free this memory.

Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
Cc: stable@vger.kernel.org
Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
---
 fs/xfs/xfs_zone_gc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
index e7b33d5a8b3d..2520e57e24a8 100644
--- a/fs/xfs/xfs_zone_gc.c
+++ b/fs/xfs/xfs_zone_gc.c
@@ -1230,7 +1230,7 @@ xfs_zone_gc_mount(
 	if (data->oz)
 		xfs_open_zone_put(data->oz);
 out_free_gc_data:
-	kfree(data);
+	xfs_zone_gc_data_free(data);
 	return error;
 }
 
-- 
2.53.0
Re: [PATCH] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()
Posted by Carlos Maiolino 1 month, 2 weeks ago
On Fri, 17 Apr 2026 12:16:30 +1000, Wilfred Mallawa wrote:
> In xfs_zone_gc_mount(), on error, a struct xfs_zone_gc_data allocated
> with xfs_zone_gc_data_alloc() is freed with kfree(), however, this
> doesn't free the underlying folios or the rmap_irecs.
> 
> Use xfs_zone_gc_data_free() to correctly free this memory.
> 
> 
> [...]

Applied to for-next, thanks!

[1/1] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()
      commit: af47a4be6a90c8bfc874f9994ac9c15813b9718b

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>
Re: [PATCH] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()
Posted by Darrick J. Wong 1 month, 4 weeks ago
On Fri, Apr 17, 2026 at 12:16:30PM +1000, Wilfred Mallawa wrote:
> From: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> 
> In xfs_zone_gc_mount(), on error, a struct xfs_zone_gc_data allocated
> with xfs_zone_gc_data_alloc() is freed with kfree(), however, this
> doesn't free the underlying folios or the rmap_irecs.
> 
> Use xfs_zone_gc_data_free() to correctly free this memory.
> 
> Fixes: 080d01c41d44 ("xfs: implement zoned garbage collection")
> Cc: stable@vger.kernel.org

Cc: <stable@vger.kernel.org> # v6.15

[autobackport plz, I need all the help I can get]

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> ---
>  fs/xfs/xfs_zone_gc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
> index e7b33d5a8b3d..2520e57e24a8 100644
> --- a/fs/xfs/xfs_zone_gc.c
> +++ b/fs/xfs/xfs_zone_gc.c
> @@ -1230,7 +1230,7 @@ xfs_zone_gc_mount(
>  	if (data->oz)
>  		xfs_open_zone_put(data->oz);
>  out_free_gc_data:
> -	kfree(data);
> +	xfs_zone_gc_data_free(data);
>  	return error;
>  }
>  
> -- 
> 2.53.0
> 
>
Re: [PATCH] xfs: fix memory leak for data allocated by xfs_zone_gc_data_alloc()
Posted by Christoph Hellwig 1 month, 4 weeks ago
On Fri, Apr 17, 2026 at 12:16:30PM +1000, Wilfred Mallawa wrote:
> From: Wilfred Mallawa <wilfred.mallawa@wdc.com>
> 
> In xfs_zone_gc_mount(), on error, a struct xfs_zone_gc_data allocated
> with xfs_zone_gc_data_alloc() is freed with kfree(), however, this
> doesn't free the underlying folios or the rmap_irecs.
> 
> Use xfs_zone_gc_data_free() to correctly free this memory.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>