Skip to content

bpo-44482: Fix very unlikely resource leak in glob in non-CPython implementations #26843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Lib/glob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Filename globbing utility."""

import contextlib
import os
import re
import fnmatch
Expand Down Expand Up @@ -90,7 +91,7 @@ def _iglob(pathname, root_dir, dir_fd, recursive, dironly):
# takes a literal basename (so it only has to check for its existence).

def _glob1(dirname, pattern, dir_fd, dironly):
names = list(_iterdir(dirname, dir_fd, dironly))
names = _listdir(dirname, dir_fd, dironly)
if not _ishidden(pattern):
names = (x for x in names if not _ishidden(x))
return fnmatch.filter(names, pattern)
Expand Down Expand Up @@ -158,9 +159,13 @@ def _iterdir(dirname, dir_fd, dironly):
except OSError:
return

def _listdir(dirname, dir_fd, dironly):
with contextlib.closing(_iterdir(dirname, dir_fd, dironly)) as it:
return list(it)

# Recursively yields relative pathnames inside a literal directory.
def _rlistdir(dirname, dir_fd, dironly):
names = list(_iterdir(dirname, dir_fd, dironly))
names = _listdir(dirname, dir_fd, dironly)
for x in names:
if not _ishidden(x):
yield x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix very unlikely resource leak in :mod:`glob` in alternate Python
implementations.