summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-02-04 19:09:17 +0000
committerNicholas Clark <nick@ccl4.org>2006-02-04 19:09:17 +0000
commit7cb608b5fc09aa914d5f91646e40ed772b6bac01 (patch)
treed87bee4dbd1d4300ece1a4a3ecc9d640f43495ed /perl.c
parentd79395463b4ec08db7bfe67c427a8c654b5904d6 (diff)
downloadperl-7cb608b5fc09aa914d5f91646e40ed772b6bac01.tar.gz
Enhance PERL_TRACK_MEMPOOL so that it also emulates the PerlHost
behaviour of freeing up all memory at thread exit. With this and tools such as valgrind you will now get warnings as soon as you read from the deallocated memory, rather than just a warning much later about freeing to the wrong pool. p4raw-id: //depot/perl@27084
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/perl.c b/perl.c
index 411caea108..48ddb7abae 100644
--- a/perl.c
+++ b/perl.c
@@ -181,6 +181,7 @@ perl_alloc_using(struct IPerlMem* ipM, struct IPerlMem* ipMS,
PL_Dir = ipD;
PL_Sock = ipS;
PL_Proc = ipP;
+ INIT_TRACK_MEMPOOL(PL_memory_debug_header, my_perl);
return my_perl;
}
@@ -205,7 +206,13 @@ perl_alloc(void)
my_perl = (PerlInterpreter*)PerlMem_malloc(sizeof(PerlInterpreter));
S_init_tls_and_interp(my_perl);
+#ifndef PERL_TRACK_MEMPOOL
return (PerlInterpreter *) ZeroD(my_perl, 1, PerlInterpreter);
+#else
+ Zero(my_perl, 1, PerlInterpreter);
+ INIT_TRACK_MEMPOOL(PL_memory_debug_header, my_perl);
+ return my_perl;
+#endif
}
#endif /* PERL_IMPLICIT_SYS */
@@ -1280,6 +1287,13 @@ Releases a Perl interpreter. See L<perlembed>.
void
perl_free(pTHXx)
{
+#ifdef PERL_TRACK_MEMPOOL
+ /* Emulate the PerlHost behaviour of free()ing all memory allocated in this
+ thread at thread exit. */
+ while(aTHXx->Imemory_debug_header.next != &(aTHXx->Imemory_debug_header))
+ safesysfree(sTHX + (char *)(aTHXx->Imemory_debug_header.next));
+#endif
+
#if defined(WIN32) || defined(NETWARE)
# if defined(PERL_IMPLICIT_SYS)
# ifdef NETWARE