summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-02-27 16:45:20 +0000
committerNicholas Clark <nick@ccl4.org>2008-02-27 16:45:20 +0000
commit4fd0a9b8690ace1bad89926e6d018a6f863761c3 (patch)
tree8c1ac30b00bf4ee9d91af555ca77fca10eb6dd27 /util.c
parent291f766ec79ed2f8f09e116381515c07bad45726 (diff)
downloadperl-4fd0a9b8690ace1bad89926e6d018a6f863761c3.tar.gz
Do the memory debug header fixup earlier to avoid valgrind screaming
under -Dm. Also, temporarily disable memory logging during thread memory freeing, as otherwise we try to log using memory we already freed. p4raw-id: //depot/perl@33388
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/util.c b/util.c
index 37e913eccb..36166fb41d 100644
--- a/util.c
+++ b/util.c
@@ -178,11 +178,11 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
ptr = (Malloc_t)PerlMem_realloc(where,size);
PERL_ALLOC_CHECK(ptr);
- DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) rfree\n",PTR2UV(where),(long)PL_an++));
- DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) realloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
-
- if (ptr != NULL) {
+ /* MUST do this fixup first, before doing ANYTHING else, as anything else
+ might allocate memory/free/move memory, and until we do the fixup, it
+ may well be chasing (and writing to) free memory. */
#ifdef PERL_TRACK_MEMPOOL
+ if (ptr != NULL) {
struct perl_memory_debug_header *const header
= (struct perl_memory_debug_header *)ptr;
@@ -198,7 +198,17 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
header->prev->next = header;
ptr = (Malloc_t)((char*)ptr+sTHX);
+ }
#endif
+
+ /* In particular, must do that fixup above before logging anything via
+ *printf(), as it can reallocate memory, which can cause SEGVs. */
+
+ DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) rfree\n",PTR2UV(where),(long)PL_an++));
+ DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) realloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
+
+
+ if (ptr != NULL) {
return ptr;
}
else if (PL_nomemok)