php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75797 Memory leak when using class_alias() in non-debug mode
Submitted: 2018-01-10 22:55 UTC Modified: -
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: aharvey@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.2Git-2018-01-10 (Git) OS: Linux x86-64
Private report: No CVE-ID: None
 [2018-01-10 22:55 UTC] aharvey@php.net
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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-22 11:44 UTC] nikic@php.net
Automatic comment on behalf of massimiliano.braglia@fazland.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2527a0fcfd949d811f7c015aa676e47a342751b8
Log: Fixed bug #75797
 [2018-08-22 11:44 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC