Skip to content

Commit 66d9f4d

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #79951
2 parents 1b0a2bb + 9d9dffe commit 66d9f4d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PHP NEWS
2929
. Fixed bug #79930 (array_merge_recursive() crashes when called with array
3030
with single reference). (Nikita)
3131
. Fixed bug #79944 (getmxrr always returns true on Alpine linux). (Nikita)
32+
. Fixed bug #79951 (Memory leak in str_replace of empty string). (Nikita)
3233

3334
- XML:
3435
. Fixed bug #79922 (Crash after multiple calls to xml_parser_free()). (cmb)

ext/standard/string.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,12 +4357,9 @@ PHPAPI void php_stripslashes(zend_string *str)
43574357
*/
43584358
static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *subject, zval *result, int case_sensitivity)
43594359
{
4360-
zval *search_entry,
4361-
*replace_entry = NULL;
4360+
zval *search_entry;
43624361
zend_string *tmp_result,
4363-
*tmp_subject_str,
4364-
*tmp_replace_entry_str = NULL,
4365-
*replace_entry_str;
4362+
*tmp_subject_str;
43664363
char *replace_value = NULL;
43674364
size_t replace_len = 0;
43684365
zend_long replace_count = 0;
@@ -4396,10 +4393,12 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s
43964393
/* Make sure we're dealing with strings. */
43974394
zend_string *tmp_search_str;
43984395
zend_string *search_str = zval_get_tmp_string(search_entry, &tmp_search_str);
4396+
zend_string *replace_entry_str, *tmp_replace_entry_str = NULL;
43994397

44004398
/* If replace is an array. */
44014399
if (Z_TYPE_P(replace) == IS_ARRAY) {
44024400
/* Get current entry */
4401+
zval *replace_entry = NULL;
44034402
while (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) {
44044403
replace_entry = &Z_ARRVAL_P(replace)->arData[replace_idx].val;
44054404
if (Z_TYPE_P(replace_entry) != IS_UNDEF) {
@@ -4456,15 +4455,12 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s
44564455
}
44574456
} else {
44584457
zend_tmp_string_release(tmp_search_str);
4458+
zend_tmp_string_release(tmp_replace_entry_str);
44594459
continue;
44604460
}
44614461

44624462
zend_tmp_string_release(tmp_search_str);
4463-
4464-
if (tmp_replace_entry_str) {
4465-
zend_string_release_ex(tmp_replace_entry_str, 0);
4466-
tmp_replace_entry_str = NULL;
4467-
}
4463+
zend_tmp_string_release(tmp_replace_entry_str);
44684464

44694465
if (subject_str == tmp_result) {
44704466
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)