-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Zend: Fix memory leak in ++/-- when overloading fetch access #11859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1500,15 +1500,9 @@ 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); | ||
|
||
/* opcodes are expected to set the result value */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This comment seems rather useless. I'd prefer just removing it. |
||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) { | ||
ZVAL_COPY(EX_VAR(opline->result.var), var_ptr); | ||
} | ||
|
@@ -1559,15 +1553,9 @@ 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); | ||
|
||
/* opcodes are expected to set the result value */ | ||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) { | ||
ZVAL_COPY(EX_VAR(opline->result.var), var_ptr); | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the op type becomes an array, but that seems minor.