diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-02-13 02:34:53 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-02-13 02:38:27 -0500 |
commit | 541bbacc5a7b5f2f98ce9b64d05b8e3bb94ca211 (patch) | |
tree | 7fe4682960eb81383c4fe94936026adc81454ce0 /libsandbox/memory.c | |
parent | tests: simplify script-2.sh a bit (diff) | |
download | sandbox-541bbacc5a7b5f2f98ce9b64d05b8e3bb94ca211.tar.gz sandbox-541bbacc5a7b5f2f98ce9b64d05b8e3bb94ca211.tar.bz2 sandbox-541bbacc5a7b5f2f98ce9b64d05b8e3bb94ca211.zip |
libsandbox: do not call x*() memory funcs in memory replacement codev1.3.7
As Maximilian points out, the internal memory funcs in libsandbox are
already called by the x*() type funcs which means error checking occurs at
the higher level. So we don't want to do it at the inner level either as
that will lose the real file/location where the memory allocation occured.
URL: http://bugs.gentoo.org/257179
Signed-off-by: Maximilian Grothusmann <maxi-gentoo@own-hero.de>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/memory.c')
-rw-r--r-- | libsandbox/memory.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/libsandbox/memory.c b/libsandbox/memory.c index 092f612..1d9f34a 100644 --- a/libsandbox/memory.c +++ b/libsandbox/memory.c @@ -3,7 +3,11 @@ * internal routines, since we can't trust the current process to have a * malloc/free implementation that is sane and available at all times. * - * Copyright 1999-2008 Gentoo Foundation + * Note that we want to check and return NULL as normal and not call other + * x*() type funcs. That way the higher levels (which are calling the x*() + * versions) will see NULL and trigger the right kind of error message. + * + * Copyright 1999-2009 Gentoo Foundation * Licensed under the GPL-2 */ @@ -42,9 +46,13 @@ void free(void *ptr) } } +/* Hrm, implement a zalloc() ? */ void *calloc(size_t nmemb, size_t size) { - return xzalloc(nmemb * size); /* dont care about overflow */ + void *ret = malloc(nmemb * size); /* dont care about overflow */ + if (ret) + memset(ret, 0, nmemb * size); + return ret; } void *realloc(void *ptr, size_t size) @@ -53,14 +61,16 @@ void *realloc(void *ptr, size_t size) size_t old_malloc_size; if (ptr == NULL) - return xmalloc(size); + return malloc(size); if (size == 0) { free(ptr); return ptr; } old_malloc_size = SB_MALLOC_TO_SIZE(ptr); - ret = xmalloc(size); + ret = malloc(size); + if (!ret) + return ret; memcpy(ret, ptr, MIN(size, old_malloc_size)); free(ptr); return ret; @@ -75,6 +85,8 @@ char *strdup(const char *s) return NULL; len = strlen(s); - ret = xmalloc(len + 1); + ret = malloc(len + 1); + if (!ret) + return ret; return memcpy(ret, s, len + 1); } |