Detect and complain on smalloc failures
authorJens Axboe <jens.axboe@oracle.com>
Thu, 31 Jul 2008 17:55:02 +0000 (19:55 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 31 Jul 2008 17:55:02 +0000 (19:55 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c

index 8b04560907b911f8bcc7a484f71964e36d055708..a52dae0f64cc270e9605b24475e87f11c228f918 100644 (file)
@@ -694,6 +694,11 @@ int add_file(struct thread_data *td, const char *fname)
        dprint(FD_FILE, "add file %s\n", fname);
 
        f = smalloc(sizeof(*f));
+       if (!f) {
+               log_err("fio: smalloc OOM\n");
+               assert(0);
+       }
+               
        f->fd = -1;
 
        dprint(FD_FILE, "resize file array to %d files\n", cur_files + 1);
@@ -712,7 +717,11 @@ int add_file(struct thread_data *td, const char *fname)
 
        sprintf(file_name + len, "%s", fname);
        f->file_name = smalloc_strdup(file_name);
-
+       if (!f->file_name) {
+               log_err("fio: smalloc OOM\n");
+               assert(0);
+       }
+       
        get_file_type(f);
 
        switch (td->o.file_lock_mode) {
@@ -905,9 +914,18 @@ void dup_files(struct thread_data *td, struct thread_data *org)
                struct fio_file *__f;
 
                __f = smalloc(sizeof(*__f));
-
+               if (!__f) {
+                       log_err("fio: smalloc OOM\n");
+                       assert(0);
+               }
+       
                if (f->file_name) {
                        __f->file_name = smalloc_strdup(f->file_name);
+                       if (!__f->file_name) {
+                               log_err("fio: smalloc OOM\n");
+                               assert(0);
+                       }
+       
                        __f->filetype = f->filetype;
                }