Flexible I/O Tester development
 help / color / mirror / Atom feed
* [PATCH] Add a check avoid segfault.
@ 2013-01-10 11:36 majianpeng
  2013-01-10 12:18 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: majianpeng @ 2013-01-10 11:36 UTC (permalink / raw)
  To: Jens Axboe; +Cc: fio

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>
---
 filesetup.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/filesetup.c b/filesetup.c
index b1ca921..324e9a6 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -1077,8 +1077,11 @@ int add_file(struct thread_data *td, const char *fname)
 		int new_size = td->o.nr_files + 1;
 
 		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;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-11  6:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10 11:36 [PATCH] Add a check avoid segfault majianpeng
2013-01-10 12:18 ` Jens Axboe
2013-01-11  0:39   ` majianpeng
2013-01-11  6:55     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox