Date: Sat, 1 Jul 2006 15:31:41 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 100399 for review Message-ID: <200607011531.k61FVfLs093100@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100399 Change 100399 by bushman@bushman_nss_ldap_cached on 2006/07/01 15:31:13 IFC Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/include/malloc_np.h#2 integrate .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/stdlib/malloc.c#3 integrate Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/include/malloc_np.h#2 (text) ==== @@ -26,12 +26,16 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/include/malloc_np.h,v 1.1 2006/03/28 22:16:03 jasone Exp $ + * $FreeBSD: src/include/malloc_np.h,v 1.2 2006/06/30 20:57:41 jasone Exp $ */ #ifndef _MALLOC_NP_H_ #define _MALLOC_NP_H_ +#include <sys/cdefs.h> +#include <sys/types.h> +__BEGIN_DECLS size_t malloc_usable_size(const void *ptr); +__END_DECLS #endif /* _MALLOC_NP_H_ */ ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/stdlib/malloc.c#3 (text+ko) ==== @@ -185,7 +185,7 @@ #endif #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.127 2006/06/20 20:38:25 jasone Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.128 2006/06/30 20:54:15 jasone Exp $"); #include "libc_private.h" #ifdef MALLOC_DEBUG @@ -659,9 +659,6 @@ * Data. */ -/* Used as a special "nil" return value for malloc(0). */ -static const int nil; - /* Number of CPUs. */ static unsigned ncpus; @@ -1642,6 +1639,7 @@ #undef POW2_CASE #undef QUANTUM_CASE assert(regind < bin->nregs); + assert(regind * size == diff); elm = regind >> (SIZEOF_INT_2POW + 3); if (elm < run->regs_minelm) @@ -2239,7 +2237,6 @@ arena_chunk_map_t mapelm; assert(ptr != NULL); - assert(ptr != &nil); assert(CHUNK_ADDR2BASE(ptr) != ptr); /* @@ -2320,7 +2317,6 @@ assert(arena->magic == ARENA_MAGIC); assert(chunk->arena == arena); assert(ptr != NULL); - assert(ptr != &nil); assert(CHUNK_ADDR2BASE(ptr) != ptr); pageind = (((uintptr_t)ptr - (uintptr_t)chunk) >> pagesize_2pow); @@ -2353,6 +2349,7 @@ /* Medium allocation. */ size = mapelm.npages << pagesize_2pow; + assert((((uintptr_t)ptr) & (size - 1)) == 0); if (opt_junk) memset(ptr, 0x5a, size); @@ -2815,7 +2812,6 @@ arena_chunk_t *chunk; assert(ptr != NULL); - assert(ptr != &nil); chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); if (chunk != ptr) { @@ -2850,7 +2846,6 @@ size_t oldsize; assert(ptr != NULL); - assert(ptr != &nil); assert(size != 0); oldsize = isalloc(ptr); @@ -2869,7 +2864,6 @@ arena_chunk_t *chunk; assert(ptr != NULL); - assert(ptr != &nil); chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); if (chunk != ptr) { @@ -3404,10 +3398,11 @@ if (size == 0) { if (opt_sysv == false) - ret = (void *)&nil; - else + size = 1; + else { ret = NULL; - goto RETURN; + goto RETURN; + } } ret = imalloc(size); @@ -3486,10 +3481,11 @@ num_size = num * size; if (num_size == 0) { if (opt_sysv == false) - ret = (void *)&nil; - else + num_size = 1; + else { ret = NULL; - goto RETURN; + goto RETURN; + } /* * Try to avoid division here. We know that it isn't possible to * overflow during multiplication if neither operand uses any of the @@ -3524,44 +3520,49 @@ { void *ret; - if (size != 0) { - if (ptr != &nil && ptr != NULL) { - assert(malloc_initialized); + if (size == 0) { + if (opt_sysv == false) + size = 1; + else { + if (ptr != NULL) + idalloc(ptr); + ret = NULL; + goto RETURN; + } + } - ret = iralloc(ptr, size); + if (ptr != NULL) { + assert(malloc_initialized); - if (ret == NULL) { - if (opt_xmalloc) { - malloc_printf("%s: (malloc) Error in" - " ralloc(%p, %zu): out of memory\n", - _getprogname(), ptr, size); - abort(); - } - errno = ENOMEM; - } - } else { - if (malloc_init()) - ret = NULL; - else - ret = imalloc(size); + ret = iralloc(ptr, size); - if (ret == NULL) { - if (opt_xmalloc) { - malloc_printf("%s: (malloc) Error in" - " ralloc(%p, %zu): out of memory\n", - _getprogname(), ptr, size); - abort(); - } - errno = ENOMEM; + if (ret == NULL) { + if (opt_xmalloc) { + malloc_printf("%s: (malloc) Error in" + " realloc(%p, %zu): out of memory\n", + _getprogname(), ptr, size); + abort(); } + errno = ENOMEM; } } else { - if (ptr != &nil && ptr != NULL) - idalloc(ptr); + if (malloc_init()) + ret = NULL; + else + ret = imalloc(size); - ret = (void *)&nil; + if (ret == NULL) { + if (opt_xmalloc) { + malloc_printf("%s: (malloc) Error in" + " realloc(%p, %zu): out of memory\n", + _getprogname(), ptr, size); + abort(); + } + errno = ENOMEM; + } } +RETURN: UTRACE(ptr, size, ret); return (ret); } @@ -3571,7 +3572,7 @@ { UTRACE(ptr, 0, 0); - if (ptr != &nil && ptr != NULL) { + if (ptr != NULL) { assert(malloc_initialized); idalloc(ptr); @@ -3592,10 +3593,7 @@ assert(ptr != NULL); - if (ptr == &nil) - return (0); - else - return (isalloc(ptr)); + return (isalloc(ptr)); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607011531.k61FVfLs093100>