From: Jes.Sorensen@redhat.com
To: neilb@suse.de
Cc: linux-raid@vger.kernel.org
Subject: [PATCH 03/13] Try to catch malloc() failures in Assemble.c
Date: Wed, 26 Oct 2011 17:30:16 +0200 [thread overview]
Message-ID: <1319643026-11501-4-git-send-email-Jes.Sorensen@redhat.com> (raw)
In-Reply-To: <1319643026-11501-1-git-send-email-Jes.Sorensen@redhat.com>
From: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
Assemble.c | 37 +++++++++++++++++++++++++++++++++++--
1 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/Assemble.c b/Assemble.c
index 2000dd0..6337681 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -706,7 +706,17 @@ int Assemble(struct supertype *st, char *mddev,
bitmap_done = 0;
content->update_private = NULL;
devices = malloc(num_devs * sizeof(*devices));
+ if (!devices) {
+ close(mdfd);
+ return -ENOMEM;
+ }
devmap = calloc(num_devs * content->array.raid_disks, 1);
+ if (!devmap) {
+ close(mdfd);
+ free(devices);
+ return -ENOMEM;
+ }
+
for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) {
char *devname = tmpdev->devname;
struct stat stb;
@@ -847,6 +857,16 @@ int Assemble(struct supertype *st, char *mddev,
int newbestcnt = i+10;
int *newbest = malloc(sizeof(int)*newbestcnt);
int c;
+ if (!newbest) {
+ if (best)
+ free(best);
+ close(mdfd);
+ free(devices);
+ free(devmap);
+ fprintf(stderr, Name ": %s unable to "
+ "allocate memory\n", __func__);
+ return -ENOMEM;
+ }
for (c=0; c < newbestcnt; c++)
if (c < bestcnt)
newbest[c] = best[c];
@@ -912,8 +932,14 @@ int Assemble(struct supertype *st, char *mddev,
/* now we have some devices that might be suitable.
* I wonder how many
*/
- avail = malloc(content->array.raid_disks);
- memset(avail, 0, content->array.raid_disks);
+ avail = calloc(content->array.raid_disks, 1);
+ if (!avail) {
+ fprintf(stderr, Name ": %s unable to allocate memory\n",
+ __func__);
+ close(mdfd);
+ free(devices);
+ free(devmap);
+ };
okcnt = 0;
sparecnt=0;
rebuilding_cnt=0;
@@ -1172,6 +1198,13 @@ int Assemble(struct supertype *st, char *mddev,
if (content->reshape_active) {
int err = 0;
int *fdlist = malloc(sizeof(int)* bestcnt);
+ if (!fdlist) {
+ fprintf(stderr, Name ": %s unable to allocate memory\n",
+ __func__);
+ close(mdfd);
+ free(devices);
+ return -ENOMEM;
+ }
if (verbose > 0)
fprintf(stderr, Name ":%s has an active reshape - checking "
"if critical section needs to be restored\n",
--
1.7.6.4
next prev parent reply other threads:[~2011-10-26 15:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-26 15:30 [PATCH 00/13] Add missing handling of malloc() failure Jes.Sorensen
2011-10-26 15:30 ` [PATCH 01/13] count_active() catch " Jes.Sorensen
2011-10-26 15:30 ` [PATCH 02/13] Catch malloc() failures Jes.Sorensen
2011-10-26 15:30 ` Jes.Sorensen [this message]
2011-10-26 15:30 ` [PATCH 04/13] Attempt to catch malloc() failure in Detail.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 05/13] Handle malloc() failure in Examine.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 06/13] Handle malloc() errors in Manage.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 07/13] Fix malloc() failure handling in Monitor.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 08/13] Handle malloc() failures in devline() Jes.Sorensen
2011-10-26 15:30 ` [PATCH 09/13] Fix malloc handling in dlink.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 10/13] Handle malloc() failure in Grow.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 11/13] Handle malloc() failure in mdopen.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 12/13] Handle malloc() failure in mdstat.c Jes.Sorensen
2011-10-26 15:30 ` [PATCH 13/13] Catch malloc() failure Jes.Sorensen
2011-10-27 4:49 ` [PATCH 00/13] Add missing handling of " NeilBrown
2011-10-27 7:39 ` Jes Sorensen
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=1319643026-11501-4-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).