summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-22 17:08:30 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-22 17:08:30 (GMT)
commitcf1c8339f94544e8fd04a85ed575efcfa5f36833 (patch)
tree84b6e05801049979a9da9995b8d95547a674e2fd
parentba6bafcfbe3c1f271e25d3ec5d5685facaecf6fd (diff)
parent4f22a8d739494d188ba0b4430ca86d93e1ed30d2 (diff)
downloadcpython-cf1c8339f94544e8fd04a85ed575efcfa5f36833.zip
cpython-cf1c8339f94544e8fd04a85ed575efcfa5f36833.tar.gz
cpython-cf1c8339f94544e8fd04a85ed575efcfa5f36833.tar.bz2
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/import.c7
2 files changed, 6 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index e102404..047f272 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
+- Issue #14084: Fix a file descriptor leak when importing a module with a
+ bad encoding.
+
- Upgrade Unicode data to Unicode 6.1.
- Issue #14040: Remove rarely used file name suffixes for C extensions
diff --git a/Python/import.c b/Python/import.c
index 8bd7a61..4871b99 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3628,11 +3628,9 @@ call_find_module(PyObject *name, PyObject *path_list)
if (fd != -1)
fd = dup(fd);
fclose(fp);
- if (fd == -1) {
- PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
- }
fp = NULL;
+ if (fd == -1)
+ return PyErr_SetFromErrno(PyExc_OSError);
}
if (fd != -1) {
if (strchr(fdp->mode, 'b') == NULL) {
@@ -3642,6 +3640,7 @@ call_find_module(PyObject *name, PyObject *path_list)
lseek(fd, 0, 0); /* Reset position */
if (found_encoding == NULL && PyErr_Occurred()) {
Py_XDECREF(pathobj);
+ close(fd);
return NULL;
}
encoding = (found_encoding != NULL) ? found_encoding :