Skip to content

Commit

Permalink
Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_…
Browse files Browse the repository at this point in the history
…restore_error_handling())
  • Loading branch information
dstogov committed Aug 18, 2020
1 parent 2d32ddb commit 8c90002
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.0.0beta2

- SPL:
. Fixed bug #79987 (Memory leak in SplFileInfo because of missing
zend_restore_error_handling()). (Dmitry)

06 Aug 2020, PHP 8.0.0beta1

Expand Down
4 changes: 4 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,16 +1224,19 @@ PHP_METHOD(SplFileInfo, getLinkTarget)

if (intern->file_name == NULL) {
if (spl_filesystem_object_get_file_name(intern) != SUCCESS) {
zend_restore_error_handling(&error_handling);
RETURN_THROWS();
}
}
#if defined(PHP_WIN32) || defined(HAVE_SYMLINK)
if (intern->file_name == NULL) {
zend_restore_error_handling(&error_handling);
php_error_docref(NULL, E_WARNING, "Empty filename");
RETURN_FALSE;
} else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) {
char expanded_path[MAXPATHLEN];
if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND )) {
zend_restore_error_handling(&error_handling);
php_error_docref(NULL, E_WARNING, "No such file or directory");
RETURN_FALSE;
}
Expand Down Expand Up @@ -1275,6 +1278,7 @@ PHP_METHOD(SplFileInfo, getRealPath)

if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) {
if (spl_filesystem_object_get_file_name(intern) != SUCCESS) {
zend_restore_error_handling(&error_handling);
RETURN_THROWS();
}
}
Expand Down
19 changes: 19 additions & 0 deletions ext/spl/tests/bug79987.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling())
--FILE--
<?php
class BadSplFileInfo extends SplFileInfo {
public function __construct() {
}
}
$x = new BadSplFileInfo();
set_error_handler(function ($type, $msg, $file, $line, $context = []) {
echo "ops\n";
});
try {
var_dump($x->getLinkTarget());
} catch (Throwable $e) {
echo $e->getMessage() . "\n";
}
--EXPECT--
Object not initialized

0 comments on commit 8c90002

Please sign in to comment.