summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAart Stuurman <aart.stuurman@copernica.com>2015-07-27 17:17:53 +0200
committerAart Stuurman <aart.stuurman@copernica.com>2015-07-27 17:17:53 +0200
commit852dce11277755735d10c8ccb84a23f615792655 (patch)
tree8137370e88d8d1da52cb3f9d1d359b8e532c054d
parentdb7cb1d6e44470b820fd5f4f4650a8c4ce392ab6 (diff)
fixed a memory leak in using Value as a function.
-rw-r--r--zend/value.cpp16
1 files 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;
}
}