From 4d325561f325c2c79230bfece89bd5cd2521e1c4 Mon Sep 17 00:00:00 2001 From: zhangliguang Date: Wed, 22 May 2019 13:32:32 +0800 Subject: examples/io_uring-cp: fix a NULL pointer dereference In case malloc fails, the fix returns NULL to avoid NULL pointer dereference. Signed-off-by: zhangliguang Signed-off-by: Jens Axboe --- examples/io_uring-cp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'examples/io_uring-cp.c') diff --git a/examples/io_uring-cp.c b/examples/io_uring-cp.c index 1dd20fc..97f61aa 100644 --- a/examples/io_uring-cp.c +++ b/examples/io_uring-cp.c @@ -81,11 +81,16 @@ static int queue_read(struct io_uring *ring, off_t size, off_t offset) struct io_uring_sqe *sqe; struct io_data *data; + data = malloc(size + sizeof(*data)); + if (!data) + return 1; + sqe = io_uring_get_sqe(ring); - if (!sqe) + if (!sqe) { + free(data); return 1; + } - data = malloc(size + sizeof(*data)); data->read = 1; data->offset = data->first_offset = offset; -- cgit