diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-15 10:38:32 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-15 10:38:32 +0100 |
commit | 549235d32738b79ec32de52a0daba875f71a97f6 (patch) | |
tree | 542bbaaa20ac8cf401825402347f55b5a19ab594 /ext/spl | |
parent | 15f713bd850977f1650b9e902b6ecfe1ac818a13 (diff) | |
parent | 8e9eeca0b3122ce3af7d0439b3619752ca1e5a83 (diff) | |
download | php-git-549235d32738b79ec32de52a0daba875f71a97f6.tar.gz |
Merge branch 'PHP-8.0'
* PHP-8.0:
Fix leak when breaking out of FilesystemIterator
Fixed bug #80600
Diffstat (limited to 'ext/spl')
-rw-r--r-- | ext/spl/spl_directory.c | 22 | ||||
-rw-r--r-- | ext/spl/tests/filesystemiterator_leak.phpt | 12 |
2 files changed, 15 insertions, 19 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 073965db71..41e877534a 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1633,15 +1633,7 @@ zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter) { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; - - if (!Z_ISUNDEF(iterator->intern.data)) { - zval *object = &iterator->intern.data; - zval_ptr_dtor(object); - } - /* Otherwise we were called from the owning object free storage handler as - * it sets iterator->intern.data to IS_UNDEF. - * We don't even need to destroy iterator->current as we didn't add a - * reference to it in move_forward or get_iterator */ + zval_ptr_dtor(&iterator->intern.data); } /* }}} */ @@ -1703,16 +1695,8 @@ static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter) static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter) { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; - - if (!Z_ISUNDEF(iterator->intern.data)) { - zval *object = &iterator->intern.data; - zval_ptr_dtor(object); - } else { - if (!Z_ISUNDEF(iterator->current)) { - zval_ptr_dtor(&iterator->current); - ZVAL_UNDEF(&iterator->current); - } - } + zval_ptr_dtor(&iterator->intern.data); + zval_ptr_dtor(&iterator->current); } /* }}} */ diff --git a/ext/spl/tests/filesystemiterator_leak.phpt b/ext/spl/tests/filesystemiterator_leak.phpt new file mode 100644 index 0000000000..9cdaeaaa3a --- /dev/null +++ b/ext/spl/tests/filesystemiterator_leak.phpt @@ -0,0 +1,12 @@ +--TEST-- +Don't leak when breaking from FilesystemIterator +--FILE-- +<?php +$iterator = new FilesystemIterator(__DIR__); +foreach ($iterator as $value) { + break; +} +?> +===DONE=== +--EXPECT-- +===DONE=== |