[PATCH] Add a check avoid segfault.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If new_size was zero or realloc failed, it would be segment fault.
So add a check.

Signed-off-by: Jianpeng Ma <majianpeng@xxxxxxxxx>
---
 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
?韬{.n?????%??檩??w?{.n?????^n?■???h?璀?{?夸z罐?+€?zf"?????i?????_璁?:+v??撸?



[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux