cellog Sat Jun 13 17:28:35 2009 UTC
Added files:
/php-src/ext/spl/tests spl_autoload_bug48541.phpt
Modified files:
/php-src/ext/spl php_spl.c
Log:
fix Bug #48541: spl_autoload_register only registers first closure, then
leaks the others
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.158&r2=1.159&diff_format=u
Index: php-src/ext/spl/php_spl.c
diff -u php-src/ext/spl/php_spl.c:1.158 php-src/ext/spl/php_spl.c:1.159
--- php-src/ext/spl/php_spl.c:1.158 Tue Jun 9 01:57:57 2009
+++ php-src/ext/spl/php_spl.c Sat Jun 13 17:28:35 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_spl.c,v 1.158 2009/06/09 01:57:57 scottmac Exp $ */
+/* $Id: php_spl.c,v 1.159 2009/06/13 17:28:35 cellog Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -503,8 +503,24 @@
alfi.func_ptr = fcc.function_handler;
obj_ptr = fcc.object_ptr;
if (Z_TYPE_P(zcallable) == IS_OBJECT) {
+ zstr lc_name;
+
+ size_t func_name_len = Z_UNISIZE(zfunc_name);
+
alfi.closure = zcallable;
Z_ADDREF_P(zcallable);
+
+ lc_name.v = Z_UNIVAL(zfunc_name).v =
erealloc(Z_UNIVAL(zfunc_name).v, func_name_len + 2 +
sizeof(zcallable->value.obj.handle));
+ memcpy(lc_name.s + func_name_len,
&(zcallable->value.obj.handle), sizeof(zcallable->value.obj.handle));
+ func_name_len += sizeof(zcallable->value.obj.handle);
+ if (Z_TYPE(zfunc_name) == IS_UNICODE) {
+ func_name_len /= sizeof(UChar);
+ Z_STRLEN(zfunc_name) = func_name_len;
+ lc_name.u[func_name_len] = 0;
+ } else {
+ Z_STRLEN(zfunc_name) = func_name_len;
+ lc_name.s[func_name_len] = '\0';
+ }
}
if (error) {
efree(error);
@@ -512,6 +528,9 @@
zend_u_str_tolower(Z_TYPE(zfunc_name), Z_UNIVAL(zfunc_name),
Z_UNILEN(zfunc_name));
if (SPL_G(autoload_functions) &&
zend_u_hash_exists(SPL_G(autoload_functions), Z_TYPE(zfunc_name),
Z_UNIVAL(zfunc_name), Z_UNILEN(zfunc_name)+1)) {
+ if (alfi.closure) {
+ Z_DELREF_P(zcallable);
+ }
goto skip;
}
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/spl_autoload_bug48541.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/spl_autoload_bug48541.phpt
+++ php-src/ext/spl/tests/spl_autoload_bug48541.phpt
--TEST--
SPL: spl_autoload_register() Bug #48541: registering multiple closures fails
with memleaks
--FILE--
<?php
$a = function ($class) {
echo "a called\n";
};
$b = function ($class) {
eval('class ' . $class . '{function __construct(){echo "foo\n";}}');
echo "b called\n";
};
spl_autoload_register($a);
spl_autoload_register($b);
$c = $a;
spl_autoload_register($c);
$c = new foo;
?>
===DONE===
--EXPECT--
a called
b called
foo
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php