logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

cvs: ZendEngine2(PHP_5_3) / zend_object_handlers.c /tests bug43450.phpt: msg#00025

Subject: cvs: ZendEngine2(PHP_5_3) / zend_object_handlers.c /tests bug43450.phpt
johannes                Fri Dec 21 20:56:33 2007 UTC

  Added files:                 (Branch: PHP_5_3)
    /ZendEngine2/tests  bug43450.phpt 

  Modified files:              
    /ZendEngine2        zend_object_handlers.c 
  Log:
  - MFH: Fix #43450 (Memory leak on some functions with implicit object 
    __toString() call) (Davic C.)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.135.2.6.2.22.2.9&r2=1.135.2.6.2.22.2.10&diff_format=u
Index: ZendEngine2/zend_object_handlers.c
diff -u ZendEngine2/zend_object_handlers.c:1.135.2.6.2.22.2.9 
ZendEngine2/zend_object_handlers.c:1.135.2.6.2.22.2.10
--- ZendEngine2/zend_object_handlers.c:1.135.2.6.2.22.2.9       Thu Nov 22 
13:27:11 2007
+++ ZendEngine2/zend_object_handlers.c  Fri Dec 21 20:56:33 2007
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_object_handlers.c,v 1.135.2.6.2.22.2.9 2007/11/22 13:27:11 dmitry 
Exp $ */
+/* $Id: zend_object_handlers.c,v 1.135.2.6.2.22.2.10 2007/12/21 20:56:33 
johannes Exp $ */
 
 #include "zend.h"
 #include "zend_globals.h"
@@ -1191,6 +1191,9 @@
                                }
                                if (Z_TYPE_P(retval) == IS_STRING) {
                                        INIT_PZVAL(writeobj);
+                                       if (readobj == writeobj) {
+                                               zval_dtor(readobj);
+                                       }
                                        ZVAL_ZVAL(writeobj, retval, 1, 1);
                                        if (Z_TYPE_P(writeobj) != type) {
                                                
convert_to_explicit_type(writeobj, type);
@@ -1199,6 +1202,9 @@
                                } else {
                                        zval_ptr_dtor(&retval);
                                        INIT_PZVAL(writeobj);
+                                       if (readobj == writeobj) {
+                                               zval_dtor(readobj);
+                                       }
                                        ZVAL_EMPTY_STRING(writeobj);
                                        zend_error(E_RECOVERABLE_ERROR, "Method 
%s::__toString() must return a string value", ce->name);
                                        return SUCCESS;
@@ -1213,15 +1219,23 @@
                        ce = Z_OBJCE_P(readobj);
                        zend_error(E_NOTICE, "Object of class %s could not be 
converted to int", ce->name);
                        INIT_PZVAL(writeobj);
+                       if (readobj == writeobj) {
+                               zval_dtor(readobj);
+                       }
                        ZVAL_LONG(writeobj, 1);
                        return SUCCESS;
                case IS_DOUBLE:
                        ce = Z_OBJCE_P(readobj);
                        zend_error(E_NOTICE, "Object of class %s could not be 
converted to double", ce->name);
                        INIT_PZVAL(writeobj);
+                       if (readobj == writeobj) {
+                               zval_dtor(readobj);
+                       }
                        ZVAL_DOUBLE(writeobj, 1);
                        return SUCCESS;
                default:
+                       INIT_PZVAL(writeobj);
+                       Z_TYPE_P(writeobj) = IS_NULL;
                        break;
        }
        return FAILURE;

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug43450.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug43450.phpt
+++ ZendEngine2/tests/bug43450.phpt
--TEST--
Bug #43450 (Memory leak on some functions with implicit object __toString() 
call)
--SKIPIF--
<?php if (!function_exists('memory_get_usage')) die('memory_get_usage() not 
installed'); ?>
--FILE--
<?php
error_reporting(E_ALL|E_STRICT);

class Foo 
{
    public function __toString()
        {
            return __CLASS__;
        }
}

$num_repeats = 100000;

$start = (memory_get_usage() / 1024) + 16;
for ($i=1;$i<$num_repeats;$i++) 
{
        $foo = new Foo();
        md5($foo);
}
$end = memory_get_peak_usage() / 1024;

if ($start < $end) {
        echo 'FAIL';
} else {
        echo 'PASS';
}

?>
--EXPECT--
PASS

-- 
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>