Test malloc result when allocation size is tunable
authorTomohiro Kusumi <tkusumi@tuxera.com>
Tue, 28 Mar 2017 20:02:51 +0000 (23:02 +0300)
committerJens Axboe <axboe@fb.com>
Tue, 28 Mar 2017 21:14:20 +0000 (15:14 -0600)
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 <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
filesetup.c

index bcf95bd5a78785b2b4431db3b522fc12378d7bcb..ce19cf0b127d294e6d8d4c012595863552598b30 100644 (file)
@@ -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) {