Commits

Anonymous committed cbfd2bf

Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.

  • Participants
  • Parent commits 963a0fb
  • Branches 3.2

Comments (0)

Files changed (2)

 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

File Python/import.c

                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();
         }