All of lore.kernel.org
 help / color / mirror / Atom feed
From: majianpeng <majianpeng@gmail.com>
To: Jens Axboe <JAxboe@fusionio.com>
Cc: fio <fio@vger.kernel.org>
Subject: [PATCH] Add a check avoid segfault.
Date: Thu, 10 Jan 2013 04:36:19 -0700	[thread overview]
Message-ID: <201301101936131638895@gmail.com> (raw)

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

             reply	other threads:[~2013-01-10 11:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-10 11:36 majianpeng [this message]
2013-01-10 12:18 ` [PATCH] Add a check avoid segfault Jens Axboe
2013-01-11  0:39   ` majianpeng
2013-01-11  6:55     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201301101936131638895@gmail.com \
    --to=majianpeng@gmail.com \
    --cc=JAxboe@fusionio.com \
    --cc=fio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.