Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f22a8d

Browse files
committed
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
1 parent 7214612 commit 4f22a8d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #14084: Fix a file descriptor leak when importing a module with a
14+
bad encoding.
15+
1316
- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED
1417
environment variable, to provide an opt-in way to protect against denial of
1518
service attacks due to hash collisions within the dict and set types. Patch

Python/import.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3195,8 +3195,10 @@ call_find_module(char *name, PyObject *path)
31953195
memory. */
31963196
found_encoding = PyTokenizer_FindEncoding(fd);
31973197
lseek(fd, 0, 0); /* Reset position */
3198-
if (found_encoding == NULL && PyErr_Occurred())
3198+
if (found_encoding == NULL && PyErr_Occurred()) {
3199+
close(fd);
31993200
return NULL;
3201+
}
32003202
encoding = (found_encoding != NULL) ? found_encoding :
32013203
(char*)PyUnicode_GetDefaultEncoding();
32023204
}

0 commit comments

Comments
 (0)