diff Python/import.c @ 75177:fcd0a67e708e

Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding.
author Antoine Pitrou <solipsis@pitrou.net>
date Wed, 22 Feb 2012 18:08:30 +0100
parents e12b8d3a3d03 cbfd2bf80db0
children 72556ff86828
line wrap: on
line diff
--- a/Python/import.c	Wed Feb 22 16:41:50 2012 +0100
+++ b/Python/import.c	Wed Feb 22 18:08:30 2012 +0100
@@ -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 :