[Python-checkins] cpython (merge 3.2 -> default): Issue #14084: Fix a file descriptor leak when importing a module with a bad
antoine.pitrou
python-checkins at python.org
Wed Feb 22 18:12:06 CET 2012
http://hg.python.org/cpython/rev/fcd0a67e708e
changeset: 75177:fcd0a67e708e
parent: 75174:ac4256a1fbe6
parent: 75176:cbfd2bf80db0
user: Antoine Pitrou <solipsis at pitrou.net>
date: Wed Feb 22 18:08:30 2012 +0100
summary:
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
files:
Misc/NEWS | 3 +++
Python/import.c | 7 +++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
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
--- a/Python/import.c
+++ b/Python/import.c
@@ -3628,11 +3628,9 @@
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 @@
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 :
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list