]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix NULL pointer oops
authorDoug Ledford <dledford@redhat.com>
Wed, 29 Oct 2008 19:05:36 +0000 (15:05 -0400)
committerNeilBrown <neilb@suse.de>
Wed, 29 Oct 2008 21:53:02 +0000 (08:53 +1100)
RAID10 is the only raid level that uses the avail char array pointer
during the enough() operation, so it was the only one that saw this.
The code in incremental assumes unconditionally that count_active will
allocate the avail char array, that it might be used by enough, and that
it will need to be freed afterward.  Once you make count_active actually
do that, then the oops goes away.

Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Incremental.c

index 0fb9afd3c8aa55717b86e8fa7ea445fb937f82f2..9c6524f2e9e7dbeb4231ceb27254d3320d8de47b 100644 (file)
@@ -543,12 +543,18 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
                if (ok != 0)
                        continue;
                st->ss->getinfo_super(st, &info);
+               if (!avail) {
+                       avail = malloc(info.array.raid_disks);
+                       if (!avail) {
+                               fprintf(stderr, Name ": out of memory.\n");
+                               exit(1);
+                       }
+                       memset(avail, 0, info.array.raid_disks);
+                       *availp = avail;
+               }
+
                if (info.disk.state & (1<<MD_DISK_SYNC))
                {
-                       if (avail == NULL) {
-                               avail = malloc(info.array.raid_disks);
-                               memset(avail, 0, info.array.raid_disks);
-                       }
                        if (cnt == 0) {
                                cnt++;
                                max_events = info.events;