diff options
author | Nicholas Clark <nick@ccl4.org> | 2006-02-04 19:09:17 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2006-02-04 19:09:17 +0000 |
commit | 7cb608b5fc09aa914d5f91646e40ed772b6bac01 (patch) | |
tree | d87bee4dbd1d4300ece1a4a3ecc9d640f43495ed /perl.c | |
parent | d79395463b4ec08db7bfe67c427a8c654b5904d6 (diff) | |
download | perl-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.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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 |