Skip to content

Commit 8c90002

Browse files
committed
Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling())
1 parent 2d32ddb commit 8c90002

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.0.0beta2
44

5+
- SPL:
6+
. Fixed bug #79987 (Memory leak in SplFileInfo because of missing
7+
zend_restore_error_handling()). (Dmitry)
58

69
06 Aug 2020, PHP 8.0.0beta1
710

ext/spl/spl_directory.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,16 +1224,19 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
12241224

12251225
if (intern->file_name == NULL) {
12261226
if (spl_filesystem_object_get_file_name(intern) != SUCCESS) {
1227+
zend_restore_error_handling(&error_handling);
12271228
RETURN_THROWS();
12281229
}
12291230
}
12301231
#if defined(PHP_WIN32) || defined(HAVE_SYMLINK)
12311232
if (intern->file_name == NULL) {
1233+
zend_restore_error_handling(&error_handling);
12321234
php_error_docref(NULL, E_WARNING, "Empty filename");
12331235
RETURN_FALSE;
12341236
} else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) {
12351237
char expanded_path[MAXPATHLEN];
12361238
if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND )) {
1239+
zend_restore_error_handling(&error_handling);
12371240
php_error_docref(NULL, E_WARNING, "No such file or directory");
12381241
RETURN_FALSE;
12391242
}
@@ -1275,6 +1278,7 @@ PHP_METHOD(SplFileInfo, getRealPath)
12751278

12761279
if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) {
12771280
if (spl_filesystem_object_get_file_name(intern) != SUCCESS) {
1281+
zend_restore_error_handling(&error_handling);
12781282
RETURN_THROWS();
12791283
}
12801284
}

ext/spl/tests/bug79987.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling())
3+
--FILE--
4+
<?php
5+
class BadSplFileInfo extends SplFileInfo {
6+
public function __construct() {
7+
}
8+
}
9+
$x = new BadSplFileInfo();
10+
set_error_handler(function ($type, $msg, $file, $line, $context = []) {
11+
echo "ops\n";
12+
});
13+
try {
14+
var_dump($x->getLinkTarget());
15+
} catch (Throwable $e) {
16+
echo $e->getMessage() . "\n";
17+
}
18+
--EXPECT--
19+
Object not initialized

0 commit comments

Comments
 (0)