With PERL_POISON defined, ensure freshly malloc()ed memory isn't zeros,
authorNicholas Clark <nick@ccl4.org>
Fri, 10 Feb 2006 14:25:33 +0000 (14:25 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 10 Feb 2006 14:25:33 +0000 (14:25 +0000)
and when PERL_TRACK_MEMPOOL is also defined scribble on any extension
added by realloc().

p4raw-id: //depot/perl@27151

util.c

diff --git a/util.c b/util.c
index c10dd29..61d4036 100644 (file)
--- a/util.c
+++ b/util.c
@@ -96,7 +96,13 @@ Perl_safesysmalloc(MEM_SIZE size)
 #ifdef PERL_TRACK_MEMPOOL
        struct perl_memory_debug_header *const header
            = (struct perl_memory_debug_header *)ptr;
+#endif
+
+#ifdef PERL_POISON
+       Poison(((char *)ptr), size, char);
+#endif
 
+#ifdef PERL_TRACK_MEMPOOL
        header->interpreter = aTHX;
        /* Link us into the list.  */
        header->prev = &PL_memory_debug_header;
@@ -180,6 +186,14 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
        struct perl_memory_debug_header *const header
            = (struct perl_memory_debug_header *)ptr;
 
+#  ifdef PERL_POISON
+       if (header->size < size) {
+           const MEM_SIZE fresh = size - header->size;
+           char *start_of_fresh = ((char *)ptr) + size;
+           Poison(start_of_fresh, fresh, char);
+       }
+#  endif
+
        header->next->prev = header;
        header->prev->next = header;