aboutsummaryrefslogtreecommitdiff
path: root/malloc
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-08-28 00:58:32 +0000
committerUlrich Drepper <drepper@redhat.com>2006-08-28 00:58:32 +0000
commit07014fcacd42d0d3a3178cb7f6b498284ae9b2c0 (patch)
tree42a525609a93609f10b67ad9c2a9197f70423d7e /malloc
parent41999a1a37a1c00864c7e390ac6c9f29ec1ae27c (diff)
downloadglibc-07014fcacd42d0d3a3178cb7f6b498284ae9b2c0.zip
glibc-07014fcacd42d0d3a3178cb7f6b498284ae9b2c0.tar.gz
glibc-07014fcacd42d0d3a3178cb7f6b498284ae9b2c0.tar.bz2
[BZ #2684]
2006-08-27 Ulrich Drepper <drepper@redhat.com> [BZ #2684] * malloc/malloc.c (public_rEALLOc): Try harder by using other arenas if allocation failed. Patch mostly by Jan Edler <jan.edler@indexengines.com>.
Diffstat (limited to 'malloc')
-rw-r--r--malloc/malloc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 5813b41..d37e521 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