diff mbox series

io_uring: fix memory leak when cache init fail

Message ID 20240923100512.64638-1-kanie@linux.alibaba.com (mailing list archive)
State New
Headers show
Series io_uring: fix memory leak when cache init fail | expand

Commit Message

Guixin Liu Sept. 23, 2024, 10:05 a.m. UTC
We should exit the percpu ref when cache init fail to free the
data memory with in struct percpu_ref.

Fixes: 206aefde4f88 ("io_uring: reduce/pack size of io_ring_ctx")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 io_uring/io_uring.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Gabriel Krisman Bertazi Sept. 23, 2024, 7:20 p.m. UTC | #1
Guixin Liu <kanie@linux.alibaba.com> writes:

> We should exit the percpu ref when cache init fail to free the
> data memory with in struct percpu_ref.
>
> Fixes: 206aefde4f88 ("io_uring: reduce/pack size of io_ring_ctx")
> Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>

Makes sense

Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
Jens Axboe Sept. 24, 2024, 4:33 a.m. UTC | #2
On Mon, 23 Sep 2024 18:05:12 +0800, Guixin Liu wrote:
> We should exit the percpu ref when cache init fail to free the
> data memory with in struct percpu_ref.
> 
> 

Applied, thanks!

[1/1] io_uring: fix memory leak when cache init fail
      commit: 638e6c7dc0d957018e466e6247fea2932c6cfb85

Best regards,
diff mbox series

Patch

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 154b25b8a613..a1cda4139c9f 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -316,7 +316,7 @@  static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
 			    sizeof(struct uring_cache));
 	ret |= io_futex_cache_init(ctx);
 	if (ret)
-		goto err;
+		goto free_ref;
 	init_completion(&ctx->ref_comp);
 	xa_init_flags(&ctx->personalities, XA_FLAGS_ALLOC1);
 	mutex_init(&ctx->uring_lock);
@@ -344,6 +344,9 @@  static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
 	io_napi_init(ctx);
 
 	return ctx;
+
+free_ref:
+	percpu_ref_exit(&ctx->refs);
 err:
 	io_alloc_cache_free(&ctx->rsrc_node_cache, kfree);
 	io_alloc_cache_free(&ctx->apoll_cache, kfree);