diff options
author | NeilBrown <neilb@suse.de> | 2012-07-09 17:14:16 +1000 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2012-07-09 17:14:16 +1000 |
commit | 503975b9d5f0696b5d2ee20ea903b859e3f60662 (patch) | |
tree | 171c9f9b9db109325fad7f81ba07671d84a085a5 /Manage.c | |
parent | c8e1a230b73c44aff5beeeb74d32e36219bed12d (diff) |
Remove scattered checks for malloc success.
malloc should never fail, and if it does it is unlikely
that anything else useful can be done. Best approach is to
abort and let some super-daemon restart.
So define xmalloc, xcalloc, xrealloc, xstrdup which don't
fail but just print a message and exit. Then use those
removing all the tests for failure.
Also replace all "malloc;memset" sequences with 'xcalloc'.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'Manage.c')
-rw-r--r-- | Manage.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -152,7 +152,7 @@ static void remove_devices(int devnum, char *path) sprintf(base, "/dev/md_d%d", -1-devnum); be = base + strlen(base); - path2 = malloc(strlen(path)+20); + path2 = xmalloc(strlen(path)+20); strcpy(path2, path); pe = path2 + strlen(path2); @@ -865,7 +865,7 @@ int Manage_subdevs(char *devname, int fd, goto abort; } if (array.active_disks < array.raid_disks) { - char *avail = calloc(array.raid_disks, 1); + char *avail = xcalloc(array.raid_disks, 1); int d; int found = 0; @@ -948,8 +948,7 @@ 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 = xcalloc(array.raid_disks, 1); for (j=0; j< tst->max_devs; j++) { mdu_disk_info_t disc2; disc2.number = j; |