On 16 בינו 2013, at 22:00, Pascal Mathis <d...@snapserv.net> wrote:

> Hi internals!
>
> I am currently developing a Zend extension. Because the Zend MM leak reports 
> are not really useful sometimes, I switched the memory manager off with the 
> environment variable USE_ZEND_ALLOC=0, so that I can use valgrind.
>
> Right now I have found some kind of memory leak. You can use every script 
> which has an exit()-call to reproduce this leak. For example:
>
> <?php exit("Memory leak example.\n"); ?>
>
> If you run this PHP script with valgrind, it will report some ugly memory 
> leak:
>
> valgrind version: valgrind-3.6.0.SVN-Debian
> PHP Version: 5.4.10 (debug)
> Configure options: --disable-all --disable-cgi --enable-debug
> ---
> Command: export USE_ZEND_ALLOC=0 && valgrind --leak-check=full 
> php-5.4.10-debug test.php
> ---
> Report:
> ==5693== HEAP SUMMARY:
> ==5693==     in use at exit: 420 bytes in 4 blocks
> ==5693==   total heap usage: 8,355 allocs, 8,351 frees, 2,503,705 bytes 
> allocated
> ==5693==
> ==5693== 420 (240 direct, 180 indirect) bytes in 1 blocks are definitely lost 
> in loss record 4 of
> ==5693==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
> ==5693==    by 0x5E08C4: _emalloc (zend_alloc.c:2423)
> ==5693==    by 0x5C11C3: compile_file (zend_language_scanner.l:551)
> ==5693==    by 0x617311: zend_execute_scripts (zend.c:1301)
> ==5693==    by 0x58A22F: php_execute_script (main.c:2482)
> ==5693==    by 0x768967: do_cli (php_cli.c:988)
> ==5693==    by 0x76987C: main (php_cli.c:1364)
> ==5693==
> ==5693== LEAK SUMMARY:
> ==5693==    definitely lost: 240 bytes in 1 blocks
> ==5693==    indirectly lost: 180 bytes in 3 blocks
> ==5693==      possibly lost: 0 bytes in 0 blocks
> ==5693==    still reachable: 0 bytes in 0 blocks
> ==5693==         suppressed: 0 bytes in 0 blocks
>
> When the Zend memory manager is turned on, everything is fine. Is this 
> behavior intended?


Yes.  The implementation of exit() will not necessarily free all
allocated blocks.  It therefore intentionally suppresses errors that
might come from the memory manager regarding leaks - but if you turn
off the memory manager and use valgrind - you'd see them.  It's not a
problem unless you actually use PHP without the memory manager in
production, which of course you should not.

Zeev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to