mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
[3.9] bpo-44482: Fix very unlikely resource leak in glob in non-CPython implementations (GH-26843). (GH-26916)
(cherry picked from commit 5c7940257e
)
This commit is contained in:
parent
fe272b7a3a
commit
4861fdaf25
2 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
"""Filename globbing utility."""
|
"""Filename globbing utility."""
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
@ -79,7 +80,7 @@ def _iglob(pathname, recursive, dironly):
|
||||||
# takes a literal basename (so it only has to check for its existence).
|
# takes a literal basename (so it only has to check for its existence).
|
||||||
|
|
||||||
def _glob1(dirname, pattern, dironly):
|
def _glob1(dirname, pattern, dironly):
|
||||||
names = list(_iterdir(dirname, dironly))
|
names = _listdir(dirname, dironly)
|
||||||
if not _ishidden(pattern):
|
if not _ishidden(pattern):
|
||||||
names = (x for x in names if not _ishidden(x))
|
names = (x for x in names if not _ishidden(x))
|
||||||
return fnmatch.filter(names, pattern)
|
return fnmatch.filter(names, pattern)
|
||||||
|
@ -130,9 +131,13 @@ def _iterdir(dirname, dironly):
|
||||||
except OSError:
|
except OSError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _listdir(dirname, dironly):
|
||||||
|
with contextlib.closing(_iterdir(dirname, dironly)) as it:
|
||||||
|
return list(it)
|
||||||
|
|
||||||
# Recursively yields relative pathnames inside a literal directory.
|
# Recursively yields relative pathnames inside a literal directory.
|
||||||
def _rlistdir(dirname, dironly):
|
def _rlistdir(dirname, dironly):
|
||||||
names = list(_iterdir(dirname, dironly))
|
names = _listdir(dirname, dironly)
|
||||||
for x in names:
|
for x in names:
|
||||||
if not _ishidden(x):
|
if not _ishidden(x):
|
||||||
yield x
|
yield x
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix very unlikely resource leak in :mod:`glob` in alternate Python
|
||||||
|
implementations.
|
Loading…
Add table
Add a link
Reference in a new issue