php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76301 Memory leak on Exception
Submitted: 2018-05-05 08:47 UTC Modified: 2020-01-05 12:11 UTC
From: volodymyr at wildwolf dot name Assigned: cmb (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 7.1.17 OS: Ubuntu 17.04 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: volodymyr at wildwolf dot name
New email:
PHP Version: OS:

 

 [2018-05-05 08:47 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-05 08:53 UTC] volodymyr at wildwolf dot name
PHP 7.2.5 (NTS/ZTS, debug/release) is not affected.

PHP 7.0.30: release builds are affected, debug build aren't.
 [2018-05-05 09:32 UTC] volodymyr at wildwolf dot name
7.2.0 is not affected either.

7.1 is affected since at least 7.1.11.
 [2020-01-05 12:11 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-01-05 12:11 UTC] cmb@php.net
Only PHP-7.3 and up are actively supported[1], so this ticket is
no longer relevant.

[1] <https://www.php.net/supported-versions.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 21:01:28 2024 UTC