diff options
author | Jens Axboe <axboe@kernel.dk> | 2019-05-20 13:33:15 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-05-20 13:33:15 -0600 |
commit | ffe3e090cd41d0977ca74fafcb452838f76ceea1 (patch) | |
tree | 8f7112ec415148635a7b64a5f74fa2a2951ee3f3 /src | |
parent | c5145a82b4cd03d30c94eb012f4baeb7407b2490 (diff) |
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 <kkourt@kkourt.io>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src')
-rw-r--r-- | src/setup.c | 8 |
1 files 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) |