summaryrefslogtreecommitdiffstats
path: root/Python
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 /Python
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c7
1 files changed, 3 insertions, 4 deletions
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 :