From 96c4eba26396130ae7c8e96d882f8ba9926031c4 Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Thu, 31 Jan 2008 21:58:09 +0000 Subject: [PATCH] fix bug #42369 (Implicit conversion to string leaks memory) add test --- ext/simplexml/simplexml.c | 5 +++++ ext/simplexml/tests/bug42369.phpt | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ext/simplexml/tests/bug42369.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 442a1359ef..b3a7e9564d 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1844,6 +1844,11 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type, void *extra } } + if (readobj == writeobj) { + INIT_PZVAL(writeobj); + zval_dtor(readobj); + } + rv = cast_object(writeobj, type, (char *)contents, extra TSRMLS_CC); if (contents) { diff --git a/ext/simplexml/tests/bug42369.phpt b/ext/simplexml/tests/bug42369.phpt new file mode 100644 index 0000000000..e5df81460d --- /dev/null +++ b/ext/simplexml/tests/bug42369.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #42369 (Implicit conversion to string leaks memory) +--SKIPIF-- + +--FILE-- +'; + $x = simplexml_load_string($xml . "foo"); + + 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 -- 2.40.0