Skip to content

Commit ab938d7

Browse files
committed
Fix memory leak with ** on array operands
1 parent 8a9df88 commit ab938d7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Zend/tests/pow_array_leak.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Memory leak on ** with result==op1 array
3+
--FILE--
4+
<?php
5+
6+
$x = [0];
7+
$x **= 1;
8+
var_dump($x);
9+
10+
$x = [0];
11+
$x **= $x;
12+
var_dump($x);
13+
14+
?>
15+
--EXPECT--
16+
int(0)
17+
int(0)

Zend/zend_operators.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,19 +1128,28 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
11281128

11291129
if (EXPECTED(op1 != op2)) {
11301130
if (Z_TYPE_P(op1) == IS_ARRAY) {
1131+
if (op1 == result) {
1132+
zval_ptr_dtor(result);
1133+
}
11311134
ZVAL_LONG(result, 0);
11321135
return SUCCESS;
11331136
} else {
11341137
zendi_convert_scalar_to_number(op1, op1_copy, result, 0);
11351138
}
11361139
if (Z_TYPE_P(op2) == IS_ARRAY) {
1140+
if (op1 == result) {
1141+
zval_ptr_dtor(result);
1142+
}
11371143
ZVAL_LONG(result, 1L);
11381144
return SUCCESS;
11391145
} else {
11401146
zendi_convert_scalar_to_number(op2, op2_copy, result, 0);
11411147
}
11421148
} else {
11431149
if (Z_TYPE_P(op1) == IS_ARRAY) {
1150+
if (op1 == result) {
1151+
zval_ptr_dtor(result);
1152+
}
11441153
ZVAL_LONG(result, 0);
11451154
return SUCCESS;
11461155
} else {

0 commit comments

Comments
 (0)