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 --- mapfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mapfile.c') diff --git a/mapfile.c b/mapfile.c index 70ff3558..fa238832 100644 --- a/mapfile.c +++ b/mapfile.c @@ -166,12 +166,12 @@ void map_fork(void) void map_add(struct map_ent **melp, int devnum, char *metadata, int uuid[4], char *path) { - struct map_ent *me = malloc(sizeof(*me)); + struct map_ent *me = xmalloc(sizeof(*me)); me->devnum = devnum; strcpy(me->metadata, metadata); memcpy(me->uuid, uuid, 16); - me->path = path ? strdup(path) : NULL; + me->path = path ? xstrdup(path) : NULL; me->next = *melp; me->bad = 0; *melp = me; @@ -237,7 +237,7 @@ int map_update(struct map_ent **mpp, int devnum, char *metadata, strcpy(mp->metadata, metadata); memcpy(mp->uuid, uuid, 16); free(mp->path); - mp->path = path ? strdup(path) : NULL; + mp->path = path ? xstrdup(path) : NULL; mp->bad = 0; break; } -- cgit v1.2.3