From 8c900022014cd7cff0d7708f3dc7041e42db97b7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 18 Aug 2020 11:08:04 +0300 Subject: [PATCH] Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling()) --- NEWS | 3 +++ ext/spl/spl_directory.c | 4 ++++ ext/spl/tests/bug79987.phpt | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 ext/spl/tests/bug79987.phpt diff --git a/NEWS b/NEWS index c0d14769a2..1f27ce6b62 100644 --- a/NEWS +++ b/NEWS @@ -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-- +getLinkTarget()); +} catch (Throwable $e) { + echo $e->getMessage() . "\n"; +} +--EXPECT-- +Object not initialized -- 2.40.0