Skip to content

Fix GH-11507: String concatenation performance regression in 8.3 #11508

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2057,16 +2057,17 @@ has_op2_string:;
}

if (result == op1) {
/* special case, perform operations on result */
result_str = zend_string_extend(op1_string, result_len, 0);
/* Free result after zend_string_extend(), as it may throw an out-of-memory error. If we
* free it before we would leave the released variable on the stack with shutdown trying
* to free it again. */
/* Extend first to drop the refcount, such that $x .= ...; may happen in-place. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release/free first, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes of course 🤦 clearly not awake anymore :p

if (free_op1_string) {
/* op1_string will be used as the result, so we should not free it */
i_zval_ptr_dtor(result);
/* Set it to NULL in case that the extension will cause an out-of-memory error.
* Otherwise the shutdown sequence will try to free this again. */
ZVAL_NULL(result);
free_op1_string = false;
}
/* special case, perform operations on result */
result_str = zend_string_extend(op1_string, result_len, 0);
/* account for the case where result_str == op1_string == op2_string and the realloc is done */
if (op1_string == op2_string) {
if (free_op2_string) {
Expand Down