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

Skip to content

Commit cf1c833

Browse files
committed
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
2 parents ba6bafc + 4f22a8d commit cf1c833

2 files changed

Lines changed: 6 additions & 4 deletions

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.3 Alpha 1?
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
- Upgrade Unicode data to Unicode 6.1.
1417

1518
- Issue #14040: Remove rarely used file name suffixes for C extensions

Python/import.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3628,11 +3628,9 @@ call_find_module(PyObject *name, PyObject *path_list)
36283628
if (fd != -1)
36293629
fd = dup(fd);
36303630
fclose(fp);
3631-
if (fd == -1) {
3632-
PyErr_SetFromErrno(PyExc_OSError);
3633-
return NULL;
3634-
}
36353631
fp = NULL;
3632+
if (fd == -1)
3633+
return PyErr_SetFromErrno(PyExc_OSError);
36363634
}
36373635
if (fd != -1) {
36383636
if (strchr(fdp->mode, 'b') == NULL) {
@@ -3642,6 +3640,7 @@ call_find_module(PyObject *name, PyObject *path_list)
36423640
lseek(fd, 0, 0); /* Reset position */
36433641
if (found_encoding == NULL && PyErr_Occurred()) {
36443642
Py_XDECREF(pathobj);
3643+
close(fd);
36453644
return NULL;
36463645
}
36473646
encoding = (found_encoding != NULL) ? found_encoding :

0 commit comments

Comments
 (0)