New submission from Serhiy Storchaka:

Since scandir iterator has no close method, the most safe way to avoid file 
descriptors leaks when use os.scandir() is accumulating yielded results into a 
list before processing them:

    entries = list(os.scandir(path))

But this doesn't save us from all leaks. If an error happened during yielding 
next entry, opened file descriptor left open.

Proposed patch makes scandir to close the file descriptor not only when an 
iteration is exhausted, but when any error (expected OSError or MemoryError) is 
raised.

This is needed to fix possible leaks in os.walk() in 3.5 (see also issue25995).

----------
components: Extension Modules
files: scandir_closedir_on_error.patch
keywords: patch
messages: 258232
nosy: benhoyt, gvanrossum, haypo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Close directory descriptor in scandir iterator on error
type: resource usage
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41616/scandir_closedir_on_error.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to