Bug #76301 [Com]: Memory leak on Exception
| From: | volodymyr at wildwolf dot name | Date: | Sat, 05 May 2018 08:53:44 +0000 |
| Subject: | Bug #76301 [Com]: Memory leak on Exception | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215050@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76301&edit=1
ID: 76301
Comment by: volodymyr at wildwolf dot name
Reported by: volodymyr at wildwolf dot name
Summary: Memory leak on Exception
Status: Open
Type: Bug
Package: Unknown/Other Function
Operating System: Ubuntu 17.04 x64
PHP Version: 7.1.17
Block user comment: N
Private report: N
New Comment:
PHP 7.2.5 (NTS/ZTS, debug/release) is not affected.
PHP 7.0.30: release builds are affected, debug build aren't.
Previous Comments:
------------------------------------------------------------------------
[2018-05-05 08:47:35] volodymyr at wildwolf dot name
Description:
------------
A simple PHPUnit test case:
```
class LeakTest extends \PHPUnit\Framework\TestCase
{
/**
* @expectedException \RuntimeException
*/
public function testLeak()
{
throw new \RuntimeException();
}
}
```
leaks when run under Valgrind:
USE_ZEND_ALLOC=0 valgrind --leak-check=full $(phpenv which php) ./phpunit
(phpunit runs
PHPUnit\TextUI\Command::main(false) to ensure clean shutdown without
exit()).
Tested this on 7.1.17 (ZTS/NTS, DEBUG/Release)
* release versions (ZTS and NTS) leak;
* debug versions (ie, built with --enable-debug) do NOT leak.
Test script:
---------------
https://github.com/sjinks/php-memory-leak-on-exception
Expected result:
----------------
$ USE_ZEND_ALLOC=0 valgrind --leak-check=full $(phpenv which php) ./phpunit
==13709== Memcheck, a memory error detector
==13709== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13709== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==13709== Command: /home/volodymyr/.phpenv/versions/7.1.17-zts-debug/bin/php ./phpunit
==13709==
PHPUnit 7.1.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.17
Configuration: /home/volodymyr/work/github/php-leaks/phpunit.xml
. 1 / 1 (100%)
Time: 2.6 seconds, Memory: 0.00MB
OK (1 test, 1 assertion)
OK
==13709==
==13709== HEAP SUMMARY:
==13709== in use at exit: 5,519 bytes in 41 blocks
==13709== total heap usage: 111,228 allocs, 111,187 frees, 18,208,664 bytes allocated
==13709==
==13709== LEAK SUMMARY:
==13709== definitely lost: 0 bytes in 0 blocks
==13709== indirectly lost: 0 bytes in 0 blocks
==13709== possibly lost: 0 bytes in 0 blocks
==13709== still reachable: 5,519 bytes in 41 blocks
==13709== suppressed: 0 bytes in 0 blocks
==13709== Reachable blocks (those to which a pointer was found) are not shown.
==13709== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==13709==
==13709== For counts of detected and suppressed errors, rerun with: -v
==13709== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Actual result:
--------------
$ USE_ZEND_ALLOC=0 valgrind --leak-check=full $(phpenv which php) ./phpunit
==13677== Memcheck, a memory error detector
==13677== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13677== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==13677== Command: /home/volodymyr/.phpenv/versions/7.1.17-zts-release/bin/php ./phpunit
==13677==
PHPUnit 7.1.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.17
Configuration: /home/volodymyr/work/github/php-leaks/phpunit.xml
. 1 / 1 (100%)
Time: 1.27 seconds, Memory: 0.00MB
OK (1 test, 1 assertion)
OK
==13677==
==13677== HEAP SUMMARY:
==13677== in use at exit: 1,774 bytes in 33 blocks
==13677== total heap usage: 81,556 allocs, 81,523 frees, 14,308,544 bytes allocated
==13677==
==13677== 72 bytes in 1 blocks are definitely lost in loss record 29 of 33
==13677== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13677== by 0x69DB58: __zend_malloc (zend_alloc.c:2838)
==13677== by 0x70C5F7: zend_objects_new (zend_objects.c:171)
==13677== by 0x6D1DE0: _object_and_properties_init (zend_API.c:1295)
==13677== by 0x77ADD5: ZEND_NEW_SPEC_UNUSED_HANDLER (zend_vm_execute.h:27938)
==13677== by 0x71D4A2: execute_ex (zend_vm_execute.h:429)
==13677== by 0x781334: zend_execute (zend_vm_execute.h:474)
==13677== by 0x6CEED1: zend_execute_scripts (zend.c:1482)
==13677== by 0x65C8EF: php_execute_script (main.c:2577)
==13677== by 0x783935: do_cli (php_cli.c:993)
==13677== by 0x250652: main (php_cli.c:1381)
==13677==
==13677== LEAK SUMMARY:
==13677== definitely lost: 72 bytes in 1 blocks
==13677== indirectly lost: 0 bytes in 0 blocks
==13677== possibly lost: 0 bytes in 0 blocks
==13677== still reachable: 1,702 bytes in 32 blocks
==13677== suppressed: 0 bytes in 0 blocks
==13677== Reachable blocks (those to which a pointer was found) are not shown.
==13677== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==13677==
==13677== For counts of detected and suppressed errors, rerun with: -v
==13677== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76301&edit=1