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 /lib.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 'lib.c')
-rw-r--r-- | lib.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -70,7 +70,7 @@ char *devnum2devname(int num) { char name[100]; fmt_devname(name,num); - return strdup(name); + return xstrdup(name); } int devname2devnum(char *name) @@ -150,8 +150,8 @@ int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s) } if ((stb->st_mode&S_IFMT)== S_IFBLK) { - char *n = strdup(name); - struct devmap *dm = malloc(sizeof(*dm)); + char *n = xstrdup(name); + struct devmap *dm = xmalloc(sizeof(*dm)); if (strncmp(n, "/dev/./", 7)==0) strcpy(n+4, name+6); if (dm) { @@ -262,9 +262,7 @@ char *conf_word(FILE *file, int allow_key) int c; int quote; int wordfound = 0; - char *word = malloc(wsize); - - if (!word) abort(); + char *word = xmalloc(wsize); while (wordfound==0) { /* at the end of a word.. */ @@ -294,8 +292,7 @@ char *conf_word(FILE *file, int allow_key) else { if (len == wsize-1) { wsize += 100; - word = realloc(word, wsize); - if (!word) abort(); + word = xrealloc(word, wsize); } word[len++] = c; } |