From 0d068a20676144e9fd6796cc77764c420d785394 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Tue, 21 Mar 2000 22:32:57 +0000 Subject: * all mallocs now use xmalloc (and so are OOM error safe), and the common error handling saves a few bytes. Thanks to Bob Tinsley for the patch. -Erik --- utility.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'utility.c') diff --git a/utility.c b/utility.c index c274bfa15..29edbf1c4 100644 --- a/utility.c +++ b/utility.c @@ -172,9 +172,7 @@ void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) i = hash_inode(statbuf->st_ino); s = name ? strlen(name) : 0; - bucket = malloc(sizeof(ino_dev_hashtable_bucket_t) + s); - if (bucket == NULL) - fatalError("Not enough memory."); + bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s); bucket->ino = statbuf->st_ino; bucket->dev = statbuf->st_dev; if (name) @@ -1003,7 +1001,7 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, if (strcmp(needle, newNeedle) == 0) return FALSE; - oldhayStack = (char *) malloc((unsigned) (strlen(haystack))); + oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack))); while (where != NULL) { foundOne++; strcpy(oldhayStack, haystack); @@ -1364,22 +1362,16 @@ extern pid_t findPidByName( char* pidName) #endif /* BB_FEATURE_USE_DEVPS_PATCH */ #endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ -#if defined BB_GUNZIP \ - || defined BB_GZIP \ - || defined BB_PRINTF \ - || defined BB_TAIL +/* this should really be farmed out to libbusybox.a */ extern void *xmalloc(size_t size) { void *cp = malloc(size); - if (cp == NULL) { - errorMsg("out of memory"); - } + if (cp == NULL) + fatalError("out of memory"); return cp; } -#endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ - #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) extern int vdprintf(int d, const char *format, va_list ap) { -- cgit v1.2.3