[PATCH 06/13] Handle malloc() errors in Manage.c

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

 



From: Jes Sorensen <Jes.Sorensen@xxxxxxxxxx>

Signed-off-by: Jes Sorensen <Jes.Sorensen@xxxxxxxxxx>
---
 Manage.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Manage.c b/Manage.c
index 2d8c916..024318b 100644
--- a/Manage.c
+++ b/Manage.c
@@ -143,6 +143,11 @@ static void remove_devices(int devnum, char *path)
 	be = base + strlen(base);
 
 	path2 = malloc(strlen(path)+20);
+	if (!path2) {
+		fprintf(stderr, Name ": %s unable to allocate memory\n",
+			__func__);
+		exit(1);
+	}
 	strcpy(path2, path);
 	pe = path2 + strlen(path2);
 	
@@ -898,8 +903,12 @@ int Manage_subdevs(char *devname, int fd,
 				 * As we are "--re-add"ing we must find a spare slot
 				 * to fill.
 				 */
-				char *used = malloc(array.raid_disks);
-				memset(used, 0, array.raid_disks);
+				char *used = calloc(array.raid_disks, 1);
+				if (!used) {
+					fprintf(stderr, Name ": %s unable to "
+						"allocate memory\n", __func__);
+					return -ENOMEM;
+				}
 				for (j=0; j< tst->max_devs; j++) {
 					mdu_disk_info_t disc2;
 					disc2.number = j;
-- 
1.7.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux