]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 22 Feb 2012 17:05:43 +0000 (18:05 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 22 Feb 2012 17:05:43 +0000 (18:05 +0100)
Misc/NEWS
Python/import.c

index ee4287bebc9f218dbaf3e457c7c7cd1486031c90..eeab400741db241d75a7a84bb3a26349d9293ee3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
 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
index e5581c5bba133c17610c73049d0303f3d93af8d9..f443ab85116bf7b849e1b06100b2f0ffab410234 100644 (file)
@@ -3195,8 +3195,10 @@ call_find_module(char *name, PyObject *path)
                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();
         }