]> granicus.if.org Git - php/commitdiff
MFH: fix bug #42369 (Implicit conversion to string leaks memory)
authorRob Richards <rrichards@php.net>
Thu, 31 Jan 2008 21:59:41 +0000 (21:59 +0000)
committerRob Richards <rrichards@php.net>
Thu, 31 Jan 2008 21:59:41 +0000 (21:59 +0000)
add test

ext/simplexml/simplexml.c
ext/simplexml/tests/bug42369.phpt [new file with mode: 0644]

index 0a3f6f72b1587d5dcc6f5a6c13b7a637443999b9..118bf0ee11258641bdea64a865f97d591e19833b 100644 (file)
@@ -1740,6 +1740,11 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
                }
        }
 
+       if (readobj == writeobj) {
+               INIT_PZVAL(writeobj);
+               zval_dtor(readobj);
+       }
+
        rv = cast_object(writeobj, type, (char *)contents TSRMLS_CC);
 
        if (contents) {
diff --git a/ext/simplexml/tests/bug42369.phpt b/ext/simplexml/tests/bug42369.phpt
new file mode 100644 (file)
index 0000000..e5df814
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #42369 (Implicit conversion to string leaks memory)
+--SKIPIF--
+<?php if (!extension_loaded('simplexml')) echo 'skip simplexml extension is not loaded'; >
+--FILE--
+<?php
+    $xml = '<?xml version="1.0" encoding="utf-8"?>';
+    $x = simplexml_load_string($xml . "<q><x>foo</x></q>");
+
+    echo 'explicit conversion' . PHP_EOL;
+    for ($i = 0; $i < 100000; $i++) {
+        md5(strval($x->x));
+    }
+
+    echo 'no conversion' . PHP_EOL;
+    for ($i = 0; $i < 100000; $i++) {
+        md5($x->x);
+    }
+
+    echo 'done' . PHP_EOL;
+?>
+--EXPECT--
+explicit conversion
+no conversion
+done
\ No newline at end of file