summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2014-11-21 16:37:08 +0100
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2014-11-21 16:37:08 +0100
commit945748c19b966fff297d9a7a1e2dfda3b0a80754 (patch)
treee1ec0249d0df7aee2f22b11e484a948fae2b0092
parent578fc01d0e6ba0be7818ad2d2533aa3a2dde3ba4 (diff)
Value::refcount() is now const, and fixed a memory leak in return values
-rw-r--r--include/value.h2
-rw-r--r--zend/callable.cpp6
-rw-r--r--zend/value.cpp10
3 files changed, 6 insertions, 12 deletions
diff --git a/include/value.h b/include/value.h
index ea56487..5c34406 100644
--- a/include/value.h
+++ b/include/value.h
@@ -1071,7 +1071,7 @@ private:
* Refcount - the number of references to the value
* @return int
*/
- int refcount();
+ int refcount() const;
protected:
/**
diff --git a/zend/callable.cpp b/zend/callable.cpp
index a85ab72..7505bbf 100644
--- a/zend/callable.cpp
+++ b/zend/callable.cpp
@@ -52,13 +52,13 @@ void Callable::invoke(INTERNAL_FUNCTION_PARAMETERS)
// get the result
Value result(callable->invoke(params));
- // detach the zval (we don't want it to be destructed)
- zval *val = result.detach();
+ // we're ready if the return value is not even used
+ if (!return_value_used) return;
// @todo php 5.6 has a RETVAL_ZVAL_FAST macro that can be used instead (and is faster)
// return a full copy of the zval, and do not destruct it
- RETVAL_ZVAL(val, 1, 0);
+ RETVAL_ZVAL(result._val, 1, 0);
}
catch (Exception &exception)
{
diff --git a/zend/value.cpp b/zend/value.cpp
index b28096a..946a41d 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -303,13 +303,7 @@ Value::~Value()
// if there were two references or less, we're going to remove a reference
// and only one reference will remain, the object will then impossible be
// a reference
- //
- // This initially seemed to be a good idea, because reference-variables
- // are hard to deal with, and a reference with only one or even zero variables
- // pointing towards it seem silly, but this line of code caused objects only
- // to be destructed when the script exits
- //
- // if (Z_REFCOUNT_P(_val) <= 2) Z_UNSET_ISREF_P(_val);
+ if (Z_REFCOUNT_P(_val) <= 2) Z_UNSET_ISREF_P(_val);
// destruct the zval (this function will decrement the reference counter,
// and only destruct if there are no other references left)
@@ -393,7 +387,7 @@ void Value::attach(struct _hashtable *hashtable)
* Retrieve the refcount
* @return int
*/
-int Value::refcount()
+int Value::refcount() const
{
return Z_REFCOUNT_P(_val);
}