]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix a problem I introduced in r4208 when reducing the space used by
authorNicholas Nethercote <njn@valgrind.org>
Wed, 24 Aug 2005 22:38:00 +0000 (22:38 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 24 Aug 2005 22:38:00 +0000 (22:38 +0000)
heap blocks.  The minimum size for redzones is now sizeof(void*), but
I forgot to ensure this.  Massif was asking for 0 byte redzones, and this
was screwing things up on 64-bit platforms, and Massif was dying very
quickly.  This should fix bugs #111090 and #111285.

The fact that Massif was this badly broken but there were only 2 bug reports
indicates that not many people are using it, at least not on AMD64.

I also added a regtest that does some basic malloc/realloc/free testing
for Massif, which would have caught this problem.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4492

coregrind/m_mallocfree.c
massif/tests/Makefile.am
massif/tests/basic_malloc.c [new file with mode: 0644]
massif/tests/basic_malloc.stderr.exp [new file with mode: 0644]
massif/tests/basic_malloc.vgtest [new file with mode: 0644]

index 9a4a6dd23e121be45cd5010a2c188a454cd9af8e..0bd0136599163a374cae6a7330dcf19ed4e1b8c5 100644 (file)
@@ -59,9 +59,9 @@ typedef UChar UByte;
 /* Layout of an in-use block:
 
       this block total szB     (sizeof(SizeT) bytes)
-      red zone bytes           (depends on Arena.rz_szB, but > sizeof(void*))
+      red zone bytes           (depends on Arena.rz_szB, but >= sizeof(void*))
       (payload bytes)
-      red zone bytes           (depends on Arena.rz_szB, but > sizeof(void*))
+      red zone bytes           (depends on Arena.rz_szB, but >= sizeof(void*))
       this block total szB     (sizeof(SizeT) bytes)
 
    Layout of a block on the free list:
@@ -375,7 +375,12 @@ void arena_init ( ArenaId aid, Char* name, SizeT rz_szB, SizeT min_sblock_szB )
    SizeT i;
    Arena* a = arenaId_to_ArenaP(aid);
    
-   vg_assert(rz_szB < 128);      // ensure reasonable size
+   // Ensure redzones are a reasonable size.  They must always be at least
+   // the size of a pointer, for holding the prev/next pointer (see the layout
+   // details at the top of this file).
+   vg_assert(rz_szB < 128);
+   if (rz_szB < sizeof(void*)) rz_szB = sizeof(void*);
+   
    vg_assert((min_sblock_szB % VKI_PAGE_SIZE) == 0);
    a->name      = name;
    a->clientmem = ( VG_AR_CLIENT == aid ? True : False );
index 0616d78024d650c1a3d219599feb8082c6b75e84..025acc0dd21179140a6b4b76432280f2293cfaca 100644 (file)
@@ -1,7 +1,13 @@
 noinst_SCRIPTS = filter_stderr
 
 EXTRA_DIST = $(noinst_SCRIPTS) \
+        basic_malloc.stderr.exp basic_malloc.vgtest \
         toobig-allocs.stderr.exp toobig-allocs.vgtest \
         true_html.stderr.exp true_html.vgtest \
         true_text.stderr.exp true_text.vgtest
 
+AM_CFLAGS   = $(WERROR) -Winline -Wall -Wshadow -g 
+
+check_PROGRAMS = \
+       basic_malloc
+
diff --git a/massif/tests/basic_malloc.c b/massif/tests/basic_malloc.c
new file mode 100644 (file)
index 0000000..7cb452c
--- /dev/null
@@ -0,0 +1,31 @@
+// In 3.0.0, Massif was badly broken on 64-bit platforms because it asked
+// zero-sized redzones, and the allocator was forgetting to round the size
+// up to sizeof(void*), which is the minimum.  This caused bugs #111090 and
+// #111285.  This test is just a gentle allocation exercise which was
+// failing.
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NN  100
+
+int main(void)
+{ 
+   int i;
+   char* a[NN];
+
+   for (i = i; i < NN; i++) {
+      a[i] = malloc(i);
+   }
+   
+   for (i = i; i < NN; i++) {
+      a[i] = realloc(a[i], NN - i);
+   }
+   
+   for (i = i; i < NN; i++) {
+      free(a[i]);
+   }
+   
+   return 0;
+}
+
diff --git a/massif/tests/basic_malloc.stderr.exp b/massif/tests/basic_malloc.stderr.exp
new file mode 100644 (file)
index 0000000..c3baf21
--- /dev/null
@@ -0,0 +1,6 @@
+
+
+Total spacetime:   
+heap:              
+heap admin:        
+stack(s):          
diff --git a/massif/tests/basic_malloc.vgtest b/massif/tests/basic_malloc.vgtest
new file mode 100644 (file)
index 0000000..c63d481
--- /dev/null
@@ -0,0 +1,2 @@
+prog: basic_malloc
+cleanup: rm massif.*.*