Add a check avoid segfault
authorJianpeng Ma <majianpeng@gmail.com>
Fri, 11 Jan 2013 07:52:55 +0000 (08:52 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 11 Jan 2013 07:52:55 +0000 (08:52 +0100)
If new_size was zero or realloc failed, it would be segment fault.
So add a check.

Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
filesetup.c

index 69eb37cd70ea9192606cc6bd4226f09f68216621..ab5cc48da71ddb317bab84109eb1845b9a7818e5 100644 (file)
@@ -1079,6 +1079,10 @@ int add_file(struct thread_data *td, const char *fname)
                dprint(FD_FILE, "resize file array to %d files\n", new_size);
 
                td->files = realloc(td->files, new_size * sizeof(f));
+               if (td->files == NULL) {
+                       log_err("fio: realloc OOM\n");
+                       assert(0);
+               }
                td->files_size = new_size;
        }
        td->files[cur_files] = f;