mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Zend: Fix memory leak in ++/-- when overloading fetch access
Closes GH-11859
This commit is contained in:
parent
35862641ba
commit
fc3df283fb
3 changed files with 36 additions and 42 deletions
36
Zend/tests/in-de-crement/overloaded_access.phpt
Normal file
36
Zend/tests/in-de-crement/overloaded_access.phpt
Normal file
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
Overloaded array access with pre increment/decrement
|
||||
--FILE--
|
||||
<?php
|
||||
set_error_handler(function($severity, $m) {
|
||||
if (str_starts_with($m, 'Indirect modification of overloaded element')) { return; }
|
||||
throw new Exception($m, $severity);
|
||||
});
|
||||
class Foo implements ArrayAccess {
|
||||
function offsetGet($index): mixed {
|
||||
return range(1, 5);
|
||||
}
|
||||
function offsetSet($index, $newval): void {
|
||||
}
|
||||
function offsetExists($index): bool {
|
||||
return true;
|
||||
}
|
||||
function offsetUnset($index): void {
|
||||
}
|
||||
}
|
||||
$foo = new Foo;
|
||||
try {
|
||||
$foo[0]++;
|
||||
} catch (Throwable $ex) {
|
||||
echo $ex->getMessage() . "\n";
|
||||
}
|
||||
$foo = new Foo;
|
||||
try {
|
||||
$foo[0]--;
|
||||
} catch (Throwable $ex) {
|
||||
echo $ex->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot increment array
|
||||
Cannot decrement array
|
|
@ -1500,13 +1500,6 @@ ZEND_VM_HELPER(zend_pre_inc_helper, VAR|CV, ANY)
|
|||
}
|
||||
}
|
||||
increment_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
@ -1559,13 +1552,6 @@ ZEND_VM_HELPER(zend_pre_dec_helper, VAR|CV, ANY)
|
|||
}
|
||||
}
|
||||
decrement_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
|
28
Zend/zend_vm_execute.h
generated
28
Zend/zend_vm_execute.h
generated
|
@ -21624,13 +21624,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_inc_help
|
|||
}
|
||||
}
|
||||
increment_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
@ -21701,13 +21694,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_dec_help
|
|||
}
|
||||
}
|
||||
decrement_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
@ -39007,13 +38993,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_inc_help
|
|||
}
|
||||
}
|
||||
increment_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
@ -39083,13 +39062,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_dec_help
|
|||
}
|
||||
}
|
||||
decrement_function(var_ptr);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
/* Smart branch expects result to be set with exceptions */
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||
}
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue