Bug #76301 [NEW]: Memory leak on Exception
| From: | volodymyr at wildwolf dot name | Date: | Sat, 05 May 2018 08:47:47 +0000 |
| Subject: | Bug #76301 [NEW]: Memory leak on Exception | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215049@lists.php.net to get a copy of this message | ||
From: volodymyr at wildwolf dot name
Operating system: Ubuntu 17.04 x64
PHP version: 7.1.17
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Memory leak on Exception
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 bug report at https://bugs.php.net/bug.php?id=76301&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76301&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76301&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76301&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76301&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76301&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76301&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76301&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76301&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76301&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76301&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76301&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76301&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76301&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76301&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76301&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76301&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76301&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76301&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76301&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76301&r=mysqlcfg