develooper Front page | perl.perl5.porters | Postings from May 2003

[PATCH 5.8.1 @19053] malloc -DDEBUGGING - more

From:
Ilya Zakharevich
Date:
May 26, 2003 00:43
Subject:
[PATCH 5.8.1 @19053] malloc -DDEBUGGING - more
Message ID:
20030526074257.GA1367@math.berkeley.edu
This is an extra patch for malloc.c.  It

  a) enables standalone compile with -DDEBUGGING too (one macro was
     missing, and one was wrongly used);

  b) makes more alignment checks in -DDEBUGGING mode;

  c) moves one check from ifdef RCHECK, to ifdef DEBUGGING (since it
     does not use extra fields introduced in RCHECK mode).

[One bug of Lynx fixed using this code...]

Enjoy,
Ilya

--- ./malloc.c-as-sent	Tue Apr  1 20:43:46 2003
+++ ./malloc.c	Mon May 26 00:37:50 2003
@@ -192,6 +192,9 @@
      # printf()-%-Conversion of UV to pointer
      UVuf				"lu"
 
+     # printf()-%-Conversion of UV to hex pointer
+     UVxf				"lx"
+
      # Alignment to use
      MEM_ALIGNBYTES			4
 
@@ -365,6 +368,9 @@
 #    ifndef UVuf
 #      define UVuf			"lu"
 #    endif
+#    ifndef UVxf
+#      define UVxf			"lx"
+#    endif
 #    ifndef Nullch
 #      define Nullch			NULL
 #    endif
@@ -1452,14 +1458,17 @@ Perl_malloc(register size_t nbytes)
 	}
 
 	/* remove from linked list */
-#if defined(RCHECK)
-	if ((PTR2UV(p)) & (MEM_ALIGNBYTES - 1)) {
+#ifdef DEBUGGING
+	if ( (PTR2UV(p) & (MEM_ALIGNBYTES - 1))
+						/* Can't get this low */
+	     || (p && PTR2UV(p) < (1<<LOG_OF_MIN_ARENA)) ) {
 	    dTHX;
 	    PerlIO_printf(PerlIO_stderr(),
 			  "Unaligned pointer in the free chain 0x%"UVxf"\n",
 			  PTR2UV(p));
 	}
-	if ((PTR2UV(p->ov_next)) & (MEM_ALIGNBYTES - 1)) {
+	if ( (PTR2UV(p->ov_next) & (MEM_ALIGNBYTES - 1))
+	     || (p->ov_next && PTR2UV(p->ov_next) < (1<<LOG_OF_MIN_ARENA)) ) {
 	    dTHX;
 	    PerlIO_printf(PerlIO_stderr(),
 			  "Unaligned `next' pointer in the free "
@@ -1958,6 +1967,10 @@ Perl_mfree(void *mp)
 
 	if (cp == NULL)
 		return;
+#ifdef DEBUGGING
+	if (PTR2UV(cp) & (MEM_ALIGNBYTES - 1))
+	    croak("%s", "wrong alignment in free()");
+#endif
 	ovp = (union overhead *)((caddr_t)cp 
 				- sizeof (union overhead) * CHUNK_SHIFT);
 #ifdef PACK_MALLOC
@@ -2092,9 +2105,9 @@ Perl_realloc(void *mp, size_t nbytes)
 				    ? "of freed memory " : "");
 		}
 #else
-		warn("%srealloc() %signored",
-		    (ovp->ov_rmagic == RMAGIC - 1 ? "" : "Bad "),
-		     ovp->ov_rmagic == RMAGIC - 1 ? "of freed memory " : "");
+		warn2("%srealloc() %signored",
+		      (ovp->ov_rmagic == RMAGIC - 1 ? "" : "Bad "),
+		      ovp->ov_rmagic == RMAGIC - 1 ? "of freed memory " : "");
 #endif
 #else
 #ifdef PERL_CORE



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About