php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63726 Memleak with static properties and internal/user classes
Submitted: 2012-12-08 10:54 UTC Modified: 2012-12-10 11:32 UTC
From: mike@php.net Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: Irrelevant OS: Arch Linux
Private report: No CVE-ID: None
 [2012-12-08 10:54 UTC] mike@php.net
Description:
------------
There may occur memory leaks, if a user class extends an internal class with 
modified static properties:

█ ~/build/php-5.4-dbg-zts-gcov$ sapi/cli/php -r 
'http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);'

█ ~/build/php-5.4-dbg-zts-gcov$ sapi/cli/php -r 
'http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL); class eh extends 
http\Object{}'
[Sat Dec  8 11:50:14 2012]  Script:  '-'
/home/mike/src/php-5.4-workdir/Zend/zend_API.c(3756) :  Freeing 0x7FC747BCE318 
(32 bytes), script=-
=== Total 1 memory leaks detected ===

http\Object::setDefaultErrorHandling() just does a 
zend_update_static_property_long()

Test script:
---------------
<?php
http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
class eh extends http\Object{}

Expected result:
----------------
<no output>

Actual result:
--------------
[Sat Dec  8 11:50:14 2012]  Script:  '-'
/home/mike/src/php-5.4-workdir/Zend/zend_API.c(3756) :  Freeing 0x7FC747BCE318 
(32 bytes), script=-
=== Total 1 memory leaks detected ===

Patches

bug63726.patch (last revision 2012-12-10 11:30 UTC by laruence@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-08 12:46 UTC] laruence@php.net
mike, where the http\object could be found? (oecl, github?)
 [2012-12-08 14:23 UTC] mike@php.net
yup, it's the DEV_2 branch
 [2012-12-09 09:21 UTC] laruence@php.net
I can not compile DEV_2 with php-5.4...
 [2012-12-09 11:08 UTC] mike@php.net
Strange... why?
 [2012-12-09 11:31 UTC] laruence@php.net
compile error:
In file included from /home/huixinchen/local/php54-
zts//include/php/main/php_ini.h:24,
                 from /home/huixinchen/local/php54-
zts//include/php/main/fopen_wrappers.h:26,
                 from /home/huixinchen/local/php54-
zts//include/php/main/php.h:398,
                 from 
/home/huixinchen/opensource/pecl/http/branches/DEV_2/php_http_api.h:23,
                 from 
/home/huixinchen/opensource/pecl/http/branches/DEV_2/php_http_curl_client.c:16:
/home/huixinchen/local/php54-zts//include/php/Zend/zend_ini.h:81: error: 
expected ‘)’ before ‘*’ token
/home/huixinchen/local/php54-zts//include/php/Zend/zend_ini.h:82: warning: no 
semicolon at end of struct or union
/home/huixinchen/local/php54-zts//include/php/Zend/zend_ini.h:94: error: 
expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
 [2012-12-09 11:37 UTC] mike@php.net
Could you please "svn up" and try again? There were some odd includes on the top 
of php_http_curl_client.c

Thank you
 [2012-12-09 12:32 UTC] laruence@php.net
compiled successfully, and reproduced this problem now :)

thanks
 [2012-12-09 13:07 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63726.patch
Revision:   1355058457
URL:        https://bugs.php.net/patch-display.php?bug=63726&patch=bug63726.patch&revision=1355058457
 [2012-12-09 13:08 UTC] laruence@php.net
dmitry, could you review this patch please? thanks
 [2012-12-09 13:08 UTC] laruence@php.net
-Assigned To: +Assigned To: dmitry
 [2012-12-09 13:20 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63726.patch
Revision:   1355059205
URL:        https://bugs.php.net/patch-display.php?bug=63726&patch=bug63726.patch&revision=1355059205
 [2012-12-10 02:39 UTC] laruence@php.net
the problem is because when doing inherit, default static members will become 
reference between parent / child.

I am not sure, is this a expect behavior(http_cookie is derived class of 
http_object):

<?php
http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);

var_dump(http\Object::getDefaultErrorHandling());
var_dump(http\Cookie::getDefaultErrorHandling());
?>

//output
int(0)
int(0)
 [2012-12-10 10:58 UTC] mike@php.net
Yes, this should be fine.

But! :)  There seems to be a similar problem with instance properties:

<?php
class MyClient extends http\Curl\Client {}
class MyPool extends http\Curl\Client\Pool {}
class MyShare extends http\Curl\Client\DataShare {}

class MyFactory extends http\Client\Factory {
    protected $driver = "curl";
    protected $persistentHandleId = "My";
    protected $clientClass = "MyClient";
    protected $clientPoolClass = "MyPool";
    protected $clientDataShareClass = "MyShare";

    protected $dummy = "foo";
}

[Mon Dec 10 11:54:43 2012]  Script:  '/home/mike/build/php-5.4-dbg-zts-
gcov/f.php'
/home/mike/src/php-5.4-workdir/Zend/zend_compile.c(3455) :  Freeing 
0x7F45B70B1B78 (5 bytes), script=/home/mike/build/php-5.4-dbg-zts-gcov/f.php
/home/mike/src/php-5.4-workdir/Zend/zend_variables.c(123) : Actual location 
(location was relayed)
[Mon Dec 10 11:54:43 2012]  Script:  '/home/mike/build/php-5.4-dbg-zts-
gcov/f.php'
/home/mike/src/php-5.4-workdir/Zend/zend_compile.c(3454) :  Freeing 
0x7F45B70B1FC8 (32 bytes), script=/home/mike/build/php-5.4-dbg-zts-gcov/f.php
Last leak repeated 4 times
=== Total 6 memory leaks detected ===
 [2012-12-10 11:11 UTC] dmitry@php.net
-Assigned To: dmitry +Assigned To: laruence
 [2012-12-10 11:11 UTC] dmitry@php.net
The patch looks good. Please commit it into 5.3 and above.
 [2012-12-10 11:30 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63726.patch
Revision:   1355139037
URL:        https://bugs.php.net/patch-display.php?bug=63726&patch=bug63726.patch&revision=1355139037
 [2012-12-10 11:32 UTC] laruence@php.net
@mike according your new comment, I updated the patch.

it should only occurred in zts version.
 [2012-12-10 12:28 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2012-12-10 12:28 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:29 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:29 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:30 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:30 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:30 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-10 12:30 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-19 17:54 UTC] derick@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2012-12-19 17:55 UTC] derick@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2014-10-07 23:20 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2014-10-07 23:20 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2014-10-07 23:31 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=3d86e6d881a5f425c3b37a85ea7f1eb5acd12b18
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 [2014-10-07 23:31 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ad553a7af237818f5d7690e97a03ffe66ec9ab37
Log: Fixed bug #63726 (Memleak with static properties and internal/user classes)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC