From ffe3e090cd41d0977ca74fafcb452838f76ceea1 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 20 May 2019 13:33:15 -0600 Subject: Fix leak of fd in io_uring_queue_init() on failure If the ring setup fails, close the fd before returning failure. Reported-by: Kornilios Kourtis Signed-off-by: Jens Axboe --- src/setup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/setup.c b/src/setup.c index 6ed64ed..8def8c9 100644 --- a/src/setup.c +++ b/src/setup.c @@ -81,7 +81,7 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags) { struct io_uring_params p; - int fd; + int fd, ret; memset(&p, 0, sizeof(p)); p.flags = flags; @@ -90,7 +90,11 @@ int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags) if (fd < 0) return fd; - return io_uring_queue_mmap(fd, &p, ring); + ret = io_uring_queue_mmap(fd, &p, ring); + if (ret) + close(fd); + + return ret; } void io_uring_queue_exit(struct io_uring *ring) -- cgit