From: DJ Delorie Date: Mon, 8 Aug 2016 22:09:25 +0000 (-0400) Subject: Various minor fixes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56414a409a70ac91719dbb1ae88f3fe1107f69c3;p=thirdparty%2Fglibc.git Various minor fixes Replace "int" with "size_t" as appropriate. Appease gcc's array-bounds warning Process tcache after hooks to support MALLOC_CHECK_ --- diff --git a/malloc/malloc.c b/malloc/malloc.c index dad7921f8e6..8008e86aa7f 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -2159,9 +2159,9 @@ struct malloc_par #if USE_TCACHE /* Maximum number of buckets to use. */ - int tcache_max; + size_t tcache_max; /* Maximum number of chunks in each bucket. */ - int tcache_count; + size_t tcache_count; #endif }; @@ -3413,10 +3413,24 @@ __libc_malloc (size_t bytes) __MTB_TRACE_ENTRY (MALLOC, bytes, NULL); + void *(*hook) (size_t, const void *) + = atomic_forced_read (__malloc_hook); + if (__builtin_expect (hook != NULL, 0)) + { + __MTB_TRACE_PATH (hook); + __MTB_THREAD_TRACE_DISABLE (); + victim = (*hook)(bytes, RETURN_ADDRESS (0)); + __MTB_THREAD_TRACE_ENABLE (); + __MTB_TRACE_RECORD (); + if (victim != NULL) + __MTB_TRACE_SET (size3, chunksize (mem2chunk (victim))); + return victim; + } + #if USE_TCACHE /* int_free also calls request2size, be careful to not pad twice. */ size_t tbytes = request2size(bytes); - int tc_idx = size2tidx (tbytes); + size_t tc_idx = size2tidx (tbytes); if (tcache.initted == 0) { @@ -3430,6 +3444,7 @@ __libc_malloc (size_t bytes) } if (tc_idx < mp_.tcache_max + && tc_idx < TCACHE_IDX /* to appease gcc */ && tcache.entries[tc_idx] != NULL && tcache.initted == 1) { @@ -3444,20 +3459,6 @@ __libc_malloc (size_t bytes) } #endif - void *(*hook) (size_t, const void *) - = atomic_forced_read (__malloc_hook); - if (__builtin_expect (hook != NULL, 0)) - { - __MTB_TRACE_PATH (hook); - __MTB_THREAD_TRACE_DISABLE (); - victim = (*hook)(bytes, RETURN_ADDRESS (0)); - __MTB_THREAD_TRACE_ENABLE (); - __MTB_TRACE_RECORD (); - if (victim != NULL) - __MTB_TRACE_SET (size3, chunksize (mem2chunk (victim))); - return victim; - } - #if 0 && USE_TCACHE /* This is fast but causes internal fragmentation, as it always pulls large chunks but puts small chunks, leading to a large @@ -4130,8 +4131,8 @@ _tcache_fill (mstate av, size_t original_nb, mchunkptr chunk) int n = chunksize(chunk) / original_nb; mchunkptr m; TCacheEntry *e; - int tc_idx = size2tidx (original_nb - SIZE_SZ); - int bits = chunk->size & SIZE_BITS; + size_t tc_idx = size2tidx (original_nb - SIZE_SZ); + size_t bits = chunk->size & SIZE_BITS; if (tc_idx > mp_.tcache_max) return chunk; @@ -4165,7 +4166,7 @@ _tcache_fill (mstate av, size_t original_nb, mchunkptr chunk) /* Given a chunk of size ACTUAL_SIZE and a user request of size DESIRED_SIZE, compute the largest ACTUAL_SIZE that would fill the tcache. */ -static int +static size_t _tcache_maxsize (INTERNAL_SIZE_T desired_size, INTERNAL_SIZE_T actual_size) { if (size2tidx(desired_size-SIZE_SZ) > mp_.tcache_max) @@ -4262,7 +4263,7 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunk of the same size, stash them in the tcache. */ - int tc_idx = size2tidx (nb-SIZE_SZ); + size_t tc_idx = size2tidx (nb-SIZE_SZ); if (tc_idx < mp_.tcache_max) { mchunkptr tc_victim; @@ -4333,7 +4334,7 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunk of the same size, stash them in the tcache. */ - int tc_idx = size2tidx (nb-SIZE_SZ); + size_t tc_idx = size2tidx (nb-SIZE_SZ); if (tc_idx < mp_.tcache_max) { mchunkptr tc_victim; @@ -4408,11 +4409,11 @@ _int_malloc (mstate av, size_t bytes) //INTERNAL_SIZE_T tcache_max = 0; if (size2tidx (nb-SIZE_SZ) <= mp_.tcache_max) { - //int tc_idx = size2tidx (bytes); + //size_t tc_idx = size2tidx (bytes); tcache_nb = nb; //tcache_max = nb * (mp_.tcache_count - tcache.counts[tc_idx]); } - int tc_idx = size2tidx (nb-SIZE_SZ); + size_t tc_idx = size2tidx (nb-SIZE_SZ); int return_cached = 0; #endif @@ -4910,7 +4911,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) #if USE_TCACHE { - int tc_idx = size2tidx (size - SIZE_SZ); + size_t tc_idx = size2tidx (size - SIZE_SZ); if (tc_idx < mp_.tcache_max && tcache.counts[tc_idx] < mp_.tcache_count