* [PATCH] io_uring: fix memory leak when cache init fail
@ 2024-09-23 10:05 Guixin Liu
2024-09-23 19:20 ` Gabriel Krisman Bertazi
2024-09-24 4:33 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Guixin Liu @ 2024-09-23 10:05 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring
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 <[email protected]>
---
io_uring/io_uring.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: fix memory leak when cache init fail
2024-09-23 10:05 [PATCH] io_uring: fix memory leak when cache init fail Guixin Liu
@ 2024-09-23 19:20 ` Gabriel Krisman Bertazi
2024-09-24 4:33 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-23 19:20 UTC (permalink / raw)
To: Guixin Liu; +Cc: axboe, asml.silence, io-uring
Guixin Liu <[email protected]> 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 <[email protected]>
Makes sense
Reviewed-by: Gabriel Krisman Bertazi <[email protected]>
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring: fix memory leak when cache init fail
2024-09-23 10:05 [PATCH] io_uring: fix memory leak when cache init fail Guixin Liu
2024-09-23 19:20 ` Gabriel Krisman Bertazi
@ 2024-09-24 4:33 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-09-24 4:33 UTC (permalink / raw)
To: asml.silence, Guixin Liu; +Cc: io-uring
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,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-24 4:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-23 10:05 [PATCH] io_uring: fix memory leak when cache init fail Guixin Liu
2024-09-23 19:20 ` Gabriel Krisman Bertazi
2024-09-24 4:33 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox