Commits

Anonymous committed fcd0a67 Merge

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

  • Participants
  • Parent commits ac4256a, cbfd2bf

Comments (0)

Files changed (2)

 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

File Python/import.c

         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) {
             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 :