diff options
author | Nikita Popov <nikic@php.net> | 2015-01-05 17:02:11 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2015-01-05 17:02:11 +0100 |
commit | 1266515e19cb30dab5c63df764d18233a234aba6 (patch) | |
tree | bb8e7ddbb307ac184350736020d4f17ddc062845 /Zend/zend_variables.c | |
parent | 411980a8bcb713694efa7656b423f8e6b2b6de48 (diff) | |
download | php-git-1266515e19cb30dab5c63df764d18233a234aba6.tar.gz |
Fix uses of zval_add_ref and add comment on usage
zval_add_ref should be used as a copy ctor, after the value was
already copied.
In particular when used with hash insertions, it should be applied
to the return value of the insert function.
Diffstat (limited to 'Zend/zend_variables.c')
-rw-r--r-- | Zend/zend_variables.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c index 91d68c3985..70f816166b 100644 --- a/Zend/zend_variables.c +++ b/Zend/zend_variables.c @@ -201,13 +201,15 @@ ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC) } } +/* This function should only be used as a copy constructor, i.e. it + * should only be called AFTER a zval has been copied to another + * location using ZVAL_COPY_VALUE. Do not call it before copying, + * otherwise a reference may be leaked. */ ZEND_API void zval_add_ref(zval *p) { if (Z_REFCOUNTED_P(p)) { if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) { - zend_reference *ref = Z_REF_P(p); ZVAL_COPY(p, Z_REFVAL_P(p)); - efree_size(ref, sizeof(zend_reference)); } else { Z_ADDREF_P(p); } |