[Python-checkins] cpython (3.2): 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:05 CET 2012


http://hg.python.org/cpython/rev/cbfd2bf80db0
changeset:   75176:cbfd2bf80db0
branch:      3.2
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Wed Feb 22 18:05:43 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 |  4 +++-
  2 files changed, 6 insertions(+), 1 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.
+
 - Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED
   environment variable, to provide an opt-in way to protect against denial of
   service attacks due to hash collisions within the dict and set types.  Patch
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -3195,8 +3195,10 @@
                memory. */
             found_encoding = PyTokenizer_FindEncoding(fd);
             lseek(fd, 0, 0); /* Reset position */
-            if (found_encoding == NULL && PyErr_Occurred())
+            if (found_encoding == NULL && PyErr_Occurred()) {
+                close(fd);
                 return NULL;
+            }
             encoding = (found_encoding != NULL) ? found_encoding :
                    (char*)PyUnicode_GetDefaultEncoding();
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list