Skip to content

Commit 3a87e26

Browse files
guixinliu1995axboe
authored andcommitted
io_uring: fix memory leak when cache init fail
Exit the percpu ref when cache init fails to free the data memory with in struct percpu_ref. Fixes: 206aefd ("io_uring: reduce/pack size of io_ring_ctx") Signed-off-by: Guixin Liu <[email protected]> Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6fa6588 commit 3a87e26

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

io_uring/io_uring.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
321321
sizeof(struct io_kiocb));
322322
ret |= io_futex_cache_init(ctx);
323323
if (ret)
324-
goto err;
324+
goto free_ref;
325325
init_completion(&ctx->ref_comp);
326326
xa_init_flags(&ctx->personalities, XA_FLAGS_ALLOC1);
327327
mutex_init(&ctx->uring_lock);
@@ -349,6 +349,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
349349
io_napi_init(ctx);
350350

351351
return ctx;
352+
353+
free_ref:
354+
percpu_ref_exit(&ctx->refs);
352355
err:
353356
io_alloc_cache_free(&ctx->rsrc_node_cache, kfree);
354357
io_alloc_cache_free(&ctx->apoll_cache, kfree);

0 commit comments

Comments
 (0)