From 503975b9d5f0696b5d2ee20ea903b859e3f60662 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 9 Jul 2012 17:14:16 +1000 Subject: 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 --- raid6check.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) (limited to 'raid6check.c') diff --git a/raid6check.c b/raid6check.c index 1d91c96a..be7a449e 100644 --- a/raid6check.c +++ b/raid6check.c @@ -106,12 +106,12 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, unsigned long long start, unsigned long long length, char *name[]) { /* read the data and p and q blocks, and check we got them right */ - char *stripe_buf = malloc(raid_disks * chunk_size); - char **stripes = malloc(raid_disks * sizeof(char*)); - char **blocks = malloc(raid_disks * sizeof(char*)); - uint8_t *p = malloc(chunk_size); - uint8_t *q = malloc(chunk_size); - int *results = malloc(chunk_size * sizeof(int)); + char *stripe_buf = xmalloc(raid_disks * chunk_size); + char **stripes = xmalloc(raid_disks * sizeof(char*)); + char **blocks = xmalloc(raid_disks * sizeof(char*)); + uint8_t *p = xmalloc(chunk_size); + uint8_t *q = xmalloc(chunk_size); + int *results = xmalloc(chunk_size * sizeof(int)); int i; int diskP, diskQ; @@ -122,16 +122,6 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, extern int tables_ready; - if((stripe_buf == NULL) || - (stripes == NULL) || - (blocks == NULL) || - (p == NULL) || - (q == NULL) || - (results == NULL)) { - err = 1; - goto exitCheck; - } - if (!tables_ready) make_tables(); @@ -340,21 +330,11 @@ int main(int argc, char *argv[]) length = (info->component_size * 512) / chunk_size - start; } - disk_name = malloc(raid_disks * sizeof(*disk_name)); - fds = malloc(raid_disks * sizeof(*fds)); - offsets = malloc(raid_disks * sizeof(*offsets)); - buf = malloc(raid_disks * chunk_size); - - if((disk_name == NULL) || - (fds == NULL) || - (offsets == NULL) || - (buf == NULL)) { - fprintf(stderr, "%s: allocation fail\n", prg); - exit_err = 5; - goto exitHere; - } + disk_name = xmalloc(raid_disks * sizeof(*disk_name)); + fds = xmalloc(raid_disks * sizeof(*fds)); + offsets = xcalloc(raid_disks, sizeof(*offsets)); + buf = xmalloc(raid_disks * chunk_size); - memset(offsets, 0, raid_disks * sizeof(*offsets)); for(i=0; i