Skip to content

Commit df08d6b

Browse files
committed
Fix leak in assign_ref with function
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.
1 parent 4a61d84 commit df08d6b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Zend/tests/assign_ref_func_leak.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Assigning the result of a non-reference function by-reference should not leak
3+
--FILE--
4+
<?php
5+
6+
function func() {
7+
return [0];
8+
}
9+
10+
$x = $y =& func();
11+
var_dump($x, $y);
12+
13+
?>
14+
--EXPECTF--
15+
Notice: Only variables should be assigned by reference in %s on line %d
16+
array(1) {
17+
[0]=>
18+
int(0)
19+
}
20+
array(1) {
21+
[0]=>
22+
int(0)
23+
}

Zend/zend_execute.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,6 @@ static zend_never_inline ZEND_COLD int zend_wrong_assign_to_variable_reference(z
596596
Z_TRY_ADDREF_P(value_ptr);
597597
value_ptr = zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
598598

599-
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
600-
ZVAL_COPY(EX_VAR(opline->result.var), value_ptr);
601-
}
602599
return 1;
603600
}
604601

0 commit comments

Comments
 (0)