diff options
author | Dmitry Stogov <dmitry@zend.com> | 2020-08-18 11:08:04 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2020-08-18 11:08:04 +0300 |
commit | 8c900022014cd7cff0d7708f3dc7041e42db97b7 (patch) | |
tree | 62cef8de9ba685f0801c00370bf51ed25bde2c76 | |
parent | 2d32ddb273bac839b4712cd8e9d2d1b3795d4e62 (diff) | |
download | php-git-8c900022014cd7cff0d7708f3dc7041e42db97b7.tar.gz |
Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling())
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/spl/spl_directory.c | 4 | ||||
-rw-r--r-- | ext/spl/tests/bug79987.phpt | 19 |
3 files changed, 26 insertions, 0 deletions
@@ -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 diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 93299470c9..0836e18bc4 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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; } @@ -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(); } } diff --git a/ext/spl/tests/bug79987.phpt b/ext/spl/tests/bug79987.phpt new file mode 100644 index 0000000000..bda5841ee7 --- /dev/null +++ b/ext/spl/tests/bug79987.phpt @@ -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 |