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 /dlink.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 'dlink.c')
-rw-r--r-- | dlink.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -8,6 +8,7 @@ #ifdef __dietlibc__ char *strncpy(char *dest, const char *src, size_t n) __THROW; #endif +void *xcalloc(size_t num, size_t size); #include "dlink.h" @@ -63,14 +64,9 @@ char *dl_strndup(char *s, int l) if (s == NULL) return NULL; n = dl_newv(char, l+1); - if (n == NULL) - return NULL; - else - { - strncpy(n, s, l); - n[l] = 0; - return n; - } + strncpy(n, s, l); + n[l] = 0; + return n; } char *dl_strdup(char *s) |