]> granicus.if.org Git - php/commitdiff
Fix leak in assign_ref with function
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 18 Dec 2019 16:18:10 +0000 (17:18 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 18 Dec 2019 16:18:10 +0000 (17:18 +0100)
As far as I can see, the retval copying is already done in all
callers of this function, so it should not be duplicated here.

Zend/tests/assign_ref_func_leak.phpt [new file with mode: 0644]
Zend/zend_execute.c

diff --git a/Zend/tests/assign_ref_func_leak.phpt b/Zend/tests/assign_ref_func_leak.phpt
new file mode 100644 (file)
index 0000000..fe4c801
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Assigning the result of a non-reference function by-reference should not leak
+--FILE--
+<?php
+
+function func() {
+    return [0];
+}
+
+$x = $y =& func();
+var_dump($x, $y);
+
+?>
+--EXPECTF--
+Notice: Only variables should be assigned by reference in %s on line %d
+array(1) {
+  [0]=>
+  int(0)
+}
+array(1) {
+  [0]=>
+  int(0)
+}
index c1ff85bff86452e07df8a93a086a9db43c65e48c..3b980e87763ad4fa3ca771ce269a520b2c35f2e3 100644 (file)
@@ -596,9 +596,6 @@ static zend_never_inline ZEND_COLD int zend_wrong_assign_to_variable_reference(z
        Z_TRY_ADDREF_P(value_ptr);
        value_ptr = zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
 
-       if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
-               ZVAL_COPY(EX_VAR(opline->result.var), value_ptr);
-       }
        return 1;
 }