From 84af30a1ed4db246621813e7fc3a41e21cef52bb Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Tue, 28 Mar 2017 23:02:51 +0300 Subject: [PATCH] Test malloc result when allocation size is tunable The allocation size td->o.max_bs[DDIR_XXX] can be specified by user, so test the result although it can be over committed on some platforms. In theory allocation size could be as large as maximum of uint. Signed-off-by: Tomohiro Kusumi Signed-off-by: Jens Axboe --- filesetup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/filesetup.c b/filesetup.c index bcf95bd5..ce19cf0b 100644 --- a/filesetup.c +++ b/filesetup.c @@ -160,6 +160,10 @@ static int extend_file(struct thread_data *td, struct fio_file *f) } b = malloc(td->o.max_bs[DDIR_WRITE]); + if (!b) { + td_verror(td, errno, "malloc"); + goto err; + } left = f->real_file_size; while (left && !td->terminate) { @@ -243,6 +247,11 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) bs = td->o.max_bs[DDIR_READ]; b = malloc(bs); + if (!b) { + td_verror(td, errno, "malloc"); + ret = 1; + goto error; + } memset(b, 0, bs); if (lseek(f->fd, f->file_offset, SEEK_SET) < 0) { -- 2.25.1