This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2684] New: realloc fails to try other arenas


realloc does not try as hard as malloc when the current arena is full.
It is possible to have a situation where realloc will fail, but manually calling
malloc and copy will succeed.
I believe this problem does not manifest itself unless you call
mallopt(M_MMAP_MAX,0) to turn off use of mmap for large requests.

In the source file malloc.c, most calls to _int_malloc() are followed by a check
that allows switching to a new arena, but this is not true in _int_realloc().

Here is a patch, fixing the bug in public_rEALLOc() because locking
considerations make it more difficult to fix in _int_realloc():

--- glibc-20050524T1606/malloc/malloc.c 2006-05-19 13:48:27.000000000 -0400
+++ glibc-fix/malloc/malloc.c   2006-05-19 15:22:23.000000000 -0400
@@ -3507,6 +3507,17 @@
   (void)mutex_unlock(&ar_ptr->mutex);
   assert(!newp || chunk_is_mmapped(mem2chunk(newp)) ||
         ar_ptr == arena_for_chunk(mem2chunk(newp)));
+
+  if (!newp) {
+    /* Try other arenas */
+    newp = public_mALLOc(bytes);
+    if (newp) {
+      MALLOC_COPY(newp, oldmem, oldsize - 2*SIZE_SZ);
+      (void)mutex_lock(&ar_ptr->mutex);
+      _int_free(ar_ptr, oldmem);
+      (void)mutex_unlock(&ar_ptr->mutex);
+    }
+  }
   return newp;
 }
 #ifdef libc_hidden_def

-- 
           Summary: realloc fails to try other arenas
           Product: glibc
           Version: 2.3.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: jan dot edler at indexengines dot com
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: any


http://sourceware.org/bugzilla/show_bug.cgi?id=2684

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]