Bug #75797 [NEW]: Memory leak when using class_alias() in non-debug mode
| From: | aharvey@php.net | Date: | Wed, 10 Jan 2018 22:55:58 +0000 |
| Subject: | Bug #75797 [NEW]: Memory leak when using class_alias() in non-debug mode | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213462@lists.php.net to get a copy of this message | ||
From: aharvey
Operating system: Linux x86-64
PHP version: 7.2Git-2018-01-10 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Memory leak when using class_alias() in non-debug mode
Description:
------------
When fast_shutdown in shutdown_executor() is non-zero (which is the
normal case when PHP isn't compiled with --enable-debug), string keys
added to the class table for aliased classes are not freed. This results
in a leak of 32 bytes on 64 bit Linux for each call of class_alias().
This isn't an issue on master due to
https://github.com/php/php-src/commit/8e01026b829f51d80d62648db9d81263454b2988,
but it appears that all other 7.x branches are currently affected. That
commit is tied up in a bunch of other GC refactoring, so simply cherry
picking it to, say, PHP-7.2 results in other problems. (Not to mention
the ABI break it would entail.)
Test script:
---------------
<?php
class C {}
class_alias(C::class, 'foo');
Expected result:
----------------
[aharvey@aharvey-mbp-linux master]$ valgrind --leak-check=full
./sapi/cli/php /tmp/test.php
==26338== Memcheck, a memory error detector
==26338== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==26338== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright
info
==26338== Command: ./sapi/cli/php /tmp/test.php
==26338==
==26338==
==26338== HEAP SUMMARY:
==26338== in use at exit: 0 bytes in 0 blocks
==26338== total heap usage: 6,553 allocs, 6,553 frees, 1,267,251 bytes
allocated
==26338==
==26338== All heap blocks were freed -- no leaks are possible
==26338==
==26338== For counts of detected and suppressed errors, rerun with: -v
==26338== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Actual result:
--------------
[aharvey@aharvey-mbp-linux 7.2]$ valgrind --leak-check=full
/opt/php/7.2/bin/php /tmp/test.php
==26331== Memcheck, a memory error detector
==26331== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==26331== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright
info
==26331== Command: /opt/php/7.2/bin/php /tmp/test.php
==26331==
==26331==
==26331== HEAP SUMMARY:
==26331== in use at exit: 1,158 bytes in 22 blocks
==26331== total heap usage: 27,180 allocs, 27,158 frees, 3,329,121
bytes allocated
==26331==
==26331== 32 bytes in 1 blocks are definitely lost in loss record 10 of
22
==26331== at 0x4C2CEDF: malloc (vg_replace_malloc.c:299)
==26331== by 0xA1E804: __zend_malloc (zend_alloc.c:2829)
==26331== by 0xA75467: zend_string_alloc (zend_string.h:134)
==26331== by 0xA75467: zend_register_class_alias_ex
(zend_API.c:2782)
==26331== by 0xAA0B7F: zif_class_alias
(zend_builtin_functions.c:1530)
==26331== by 0xC11330: ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER
(zend_vm_execute.h:573)
==26331== by 0xC11330: execute_ex (zend_vm_execute.h:59731)
==26331== by 0xC284AA: zend_execute (zend_vm_execute.h:63760)
==26331== by 0xA671A4: zend_execute_scripts (zend.c:1496)
==26331== by 0x9AC153: php_execute_script (main.c:2590)
==26331== by 0xC2BE18: do_cli (php_cli.c:1011)
==26331== by 0xC2D1DF: main (php_cli.c:1404)
==26331==
==26331== LEAK SUMMARY:
==26331== definitely lost: 32 bytes in 1 blocks
==26331== indirectly lost: 0 bytes in 0 blocks
==26331== possibly lost: 0 bytes in 0 blocks
==26331== still reachable: 1,126 bytes in 21 blocks
==26331== suppressed: 0 bytes in 0 blocks
==26331== Reachable blocks (those to which a pointer was found) are not
shown.
==26331== To see them, rerun with: --leak-check=full
--show-leak-kinds=all
==26331==
==26331== For counts of detected and suppressed errors, rerun with: -v
==26331== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
--
Edit bug report at https://bugs.php.net/bug.php?id=75797&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75797&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75797&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75797&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75797&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75797&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75797&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75797&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75797&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75797&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75797&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75797&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75797&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75797&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75797&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75797&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75797&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75797&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75797&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75797&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75797&r=mysqlcfg