Skip to content

Fix memory leaks in array_any() / array_all() #17977

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
17 changes: 13 additions & 4 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6628,7 +6628,8 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
ZVAL_COPY(&args[0], operand);

zend_result result = zend_call_function(&fci, &fci_cache);
if (EXPECTED(result == SUCCESS)) {
ZEND_ASSERT(result == SUCCESS);
if (EXPECTED(!Z_ISUNDEF(retval))) {
int retval_true;

retval_true = zend_is_true(&retval);
Expand Down Expand Up @@ -6656,7 +6657,7 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&args[1]);

if (UNEXPECTED(result != SUCCESS)) {
if (UNEXPECTED(Z_ISUNDEF(retval))) {
return FAILURE;
}
} ZEND_HASH_FOREACH_END();
Expand Down Expand Up @@ -6725,7 +6726,11 @@ PHP_FUNCTION(array_any)
RETURN_THROWS();
}

RETURN_BOOL(Z_TYPE_P(return_value) != IS_UNDEF);
bool retval = !Z_ISUNDEF_P(return_value);
if (Z_TYPE_P(return_value) == IS_STRING) {
zval_ptr_dtor_str(return_value);
}
RETURN_BOOL(retval);
}
/* }}} */

Expand All @@ -6745,7 +6750,11 @@ PHP_FUNCTION(array_all)
RETURN_THROWS();
}

RETURN_BOOL(Z_TYPE_P(return_value) == IS_UNDEF);
bool retval = Z_ISUNDEF_P(return_value);
if (Z_TYPE_P(return_value) == IS_STRING) {
zval_ptr_dtor_str(return_value);
}
RETURN_BOOL(retval);
}
/* }}} */

Expand Down
Loading