From 852dce11277755735d10c8ccb84a23f615792655 Mon Sep 17 00:00:00 2001 From: Aart Stuurman Date: Mon, 27 Jul 2015 17:17:53 +0200 Subject: fixed a memory leak in using Value as a function. --- zend/value.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/zend/value.cpp b/zend/value.cpp index 5354904..86b658c 100644 --- a/zend/value.cpp +++ b/zend/value.cpp @@ -951,9 +951,19 @@ static Value do_exec(zval *const *object, zval *method, int argc, zval ***params // was an exception thrown inside the function? In that case we throw a C++ new exception // to give the C++ code the chance to catch it if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); - - // no (additional) exception was thrown - return retval ? Value(retval) : nullptr; + + // leap out if nothing was returned + if (!retval) return nullptr; + + // wrap the retval in a value + Php::Value result(retval); + + // destruct the retval (this just decrements the refcounter, which is ok, because + // it is already wrapped in a Php::Value so still has 1 reference) + zval_ptr_dtor(&retval); + + // done + return result; } } -- cgit v1.2.3