summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2014-12-22 15:45:06 +0100
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2014-12-22 15:45:06 +0100
commit38135ce4ab49c06799df08cfff4bc8d6f67e5fc7 (patch)
treea7bcacaff7fabb576eda21d507a638124e61ca58
parentff9a22782a7d28b11af0ff2d3948a196ab12d003 (diff)
Corrected an incorrect refcount when cloning a Php::Value, this should fix the memory leak in issue #153
-rw-r--r--include/value.h3
-rw-r--r--zend/parametersimpl.h2
-rw-r--r--zend/value.cpp26
3 files changed, 17 insertions, 14 deletions
diff --git a/include/value.h b/include/value.h
index 5c34406..7bdd853 100644
--- a/include/value.h
+++ b/include/value.h
@@ -110,7 +110,6 @@ public:
* Wrap object around zval
* @param zval Zval to wrap
* @param ref Force this to be a reference
- * @param tsrm_ls Optional pointer to thread safe data
*/
Value(struct _zval_struct *zval, bool ref=false);
@@ -655,7 +654,7 @@ public:
/**
* Cast to a number
- * @return uint64_t
+ * @return int64_t
*/
operator int64_t () const
{
diff --git a/zend/parametersimpl.h b/zend/parametersimpl.h
index fd14238..2841c75 100644
--- a/zend/parametersimpl.h
+++ b/zend/parametersimpl.h
@@ -36,7 +36,7 @@ public:
zval **arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (argc-i));
// append value
- push_back(Value(*arg));
+ emplace_back(*arg);
}
}
diff --git a/zend/value.cpp b/zend/value.cpp
index 959dbe7..64bdb0e 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -157,10 +157,8 @@ Value::Value(double value)
* @param ref Force this to be a reference
*/
Value::Value(struct _zval_struct *val, bool ref)
+: _val(val)
{
- // just copy the zval into this object
- _val = val;
-
// if the variable is not already a reference, and it has more than one
// variable pointing to it, we should seperate it so that any changes
// we're going to make will not change the other variable
@@ -169,13 +167,13 @@ Value::Value(struct _zval_struct *val, bool ref)
// separate the zval
SEPARATE_ZVAL_IF_NOT_REF(&_val);
}
-
+
// we see ourselves as reference too
Z_ADDREF_P(_val);
-
+
// we're ready if we do not have to force it as a reference
if (!ref || Z_ISREF_P(_val)) return;
-
+
// make this a reference
Z_SET_ISREF_P(_val);
}
@@ -1528,18 +1526,24 @@ Value Value::clone() const
{
// the zval that will hold the copy
zval *copy;
-
+
// allocate memory
ALLOC_ZVAL(copy);
-
+
// copy the data
INIT_PZVAL_COPY(copy, _val);
-
+
// run the copy constructor to ensure that everything gets copied
zval_copy_ctor(copy);
-
+
+ // wrap it using the Value(zval*) constructor, this will +1 the refcount!!!!
+ Value output(copy);
+
+ // -1 the refcount to avoid future leaks
+ Z_DELREF_P(copy);
+
// done
- return Value(copy);
+ return output;
}
/**