Skip to content

Commit 80b7316

Browse files
committed
Fix memory leak in array_diff() with custom type checks
Closes GH-20428.
1 parent ae01a8a commit 80b7316

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PHP NEWS
1313
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
1414
buffer). (Arnaud)
1515

16+
- Standard:
17+
. Fix memory leak in array_diff() with custom type checks. (ndossche)
18+
1619
- Tidy:
1720
. Fixed bug GH-20374 (PHP with tidy and custom-tags). (ndossche)
1821

ext/standard/array.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,6 +5762,7 @@ PHP_FUNCTION(array_diff)
57625762

57635763
for (i = 1; i < argc; i++) {
57645764
if (Z_TYPE(args[i]) != IS_ARRAY) {
5765+
zend_tmp_string_release(tmp_search_str);
57655766
zend_argument_type_error(i + 1, "must be of type array, %s given", zend_zval_value_name(&args[i]));
57665767
RETURN_THROWS();
57675768
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
array_diff() memory leak with custom type checks
3+
--FILE--
4+
<?php
5+
6+
try {
7+
array_diff([123], 'x');
8+
} catch (TypeError $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
array_diff(): Argument #2 must be of type array, string given

0 commit comments

Comments
 (0)