Skip to content

Commit

Permalink
Fix memory leak with ** on array operands
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 26, 2019
1 parent 8a9df88 commit ab938d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Zend/tests/pow_array_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Memory leak on ** with result==op1 array
--FILE--
<?php

$x = [0];
$x **= 1;
var_dump($x);

$x = [0];
$x **= $x;
var_dump($x);

?>
--EXPECT--
int(0)
int(0)
9 changes: 9 additions & 0 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,19 +1128,28 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {

if (EXPECTED(op1 != op2)) {
if (Z_TYPE_P(op1) == IS_ARRAY) {
if (op1 == result) {
zval_ptr_dtor(result);
}
ZVAL_LONG(result, 0);
return SUCCESS;
} else {
zendi_convert_scalar_to_number(op1, op1_copy, result, 0);
}
if (Z_TYPE_P(op2) == IS_ARRAY) {
if (op1 == result) {
zval_ptr_dtor(result);
}
ZVAL_LONG(result, 1L);
return SUCCESS;
} else {
zendi_convert_scalar_to_number(op2, op2_copy, result, 0);
}
} else {
if (Z_TYPE_P(op1) == IS_ARRAY) {
if (op1 == result) {
zval_ptr_dtor(result);
}
ZVAL_LONG(result, 0);
return SUCCESS;
} else {
Expand Down

0 comments on commit ab938d7

Please sign in to comment.