summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangliguang <zhangliguang@linux.alibaba.com>2019-05-22 13:32:32 +0800
committerJens Axboe <axboe@kernel.dk>2019-05-22 08:46:28 -0600
commit4d325561f325c2c79230bfece89bd5cd2521e1c4 (patch)
tree2b92687602e9f07ab9534ed12ffd615157802484
parent2e719820d47cdb48308265f95547d2c9458bbfe7 (diff)
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 <zhangliguang@linux.alibaba.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/io_uring-cp.c9
1 files changed, 7 insertions, 2 deletions
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;