Skip to content

Commit dd85846

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79951
2 parents 5613565 + 66d9f4d commit dd85846

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ext/standard/string.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4090,11 +4090,8 @@ PHPAPI void php_stripslashes(zend_string *str)
40904090
/* {{{ php_str_replace_in_subject */
40914091
static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_string *subject_str, zval *result, int case_sensitivity)
40924092
{
4093-
zval *search_entry,
4094-
*replace_entry = NULL;
4095-
zend_string *tmp_result,
4096-
*tmp_replace_entry_str = NULL,
4097-
*replace_entry_str;
4093+
zval *search_entry;
4094+
zend_string *tmp_result;
40984095
char *replace_value = NULL;
40994096
size_t replace_len = 0;
41004097
zend_long replace_count = 0;
@@ -4124,10 +4121,12 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_st
41244121
/* Make sure we're dealing with strings. */
41254122
zend_string *tmp_search_str;
41264123
zend_string *search_str = zval_get_tmp_string(search_entry, &tmp_search_str);
4124+
zend_string *replace_entry_str, *tmp_replace_entry_str = NULL;
41274125

41284126
/* If replace is an array. */
41294127
if (Z_TYPE_P(replace) == IS_ARRAY) {
41304128
/* Get current entry */
4129+
zval *replace_entry = NULL;
41314130
while (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) {
41324131
replace_entry = &Z_ARRVAL_P(replace)->arData[replace_idx].val;
41334132
if (Z_TYPE_P(replace_entry) != IS_UNDEF) {
@@ -4184,15 +4183,12 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_st
41844183
}
41854184
} else {
41864185
zend_tmp_string_release(tmp_search_str);
4186+
zend_tmp_string_release(tmp_replace_entry_str);
41874187
continue;
41884188
}
41894189

41904190
zend_tmp_string_release(tmp_search_str);
4191-
4192-
if (tmp_replace_entry_str) {
4193-
zend_string_release_ex(tmp_replace_entry_str, 0);
4194-
tmp_replace_entry_str = NULL;
4195-
}
4191+
zend_tmp_string_release(tmp_replace_entry_str);
41964192

41974193
if (subject_str == tmp_result) {
41984194
zend_string_delref(subject_str);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #79951: Memory leak in str_replace of empty string
3+
--FILE--
4+
<?php
5+
6+
var_dump(str_replace([""], [1000], "foo"));
7+
8+
?>
9+
--EXPECT--
10+
string(3) "foo"

0 commit comments

Comments
 (0)