From: Ulrich Drepper Date: Mon, 28 Aug 2006 00:58:32 +0000 (+0000) Subject: [BZ #2684] X-Git-Tag: cvs/fedora-glibc-20060828T1903~1 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=07014fcacd42d0d3a3178cb7f6b498284ae9b2c0;p=glibc.git [BZ #2684] 2006-08-27 Ulrich Drepper [BZ #2684] * malloc/malloc.c (public_rEALLOc): Try harder by using other arenas if allocation failed. Patch mostly by Jan Edler . --- diff --git a/ChangeLog b/ChangeLog index 61a0696850..3975e02de0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-08-27 Ulrich Drepper + + [BZ #2684] + * malloc/malloc.c (public_rEALLOc): Try harder by using other + arenas if allocation failed. + Patch mostly by Jan Edler . + 2006-08-26 Ulrich Drepper * malloc/malloc.c (bin_at): Rewrite to be more clear and to not diff --git a/malloc/malloc.c b/malloc/malloc.c index 5813b419c7..d37e521367 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3625,6 +3625,29 @@ public_rEALLOc(Void_t* oldmem, size_t bytes) (void)mutex_unlock(&ar_ptr->mutex); assert(!newp || chunk_is_mmapped(mem2chunk(newp)) || ar_ptr == arena_for_chunk(mem2chunk(newp))); + + if (newp == NULL) + { + /* Try harder to allocate memory in other arenas. */ + newp = public_mALLOc(bytes); + if (newp != NULL) + { + MALLOC_COPY (newp, oldmem, oldsize - 2 * SIZE_SZ); +#if THREAD_STATS + if(!mutex_trylock(&ar_ptr->mutex)) + ++(ar_ptr->stat_lock_direct); + else { + (void)mutex_lock(&ar_ptr->mutex); + ++(ar_ptr->stat_lock_wait); + } +#else + (void)mutex_lock(&ar_ptr->mutex); +#endif + _int_free(ar_ptr, oldmem); + (void)mutex_unlock(&ar_ptr->mutex); + } + } + return newp; } #ifdef libc_hidden_def