]> granicus.if.org Git - python/commitdiff
Bug #1674503: close the file opened by execfile() in an error condition.
authorGeorg Brandl <georg@python.org>
Tue, 6 Mar 2007 12:16:52 +0000 (12:16 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 6 Mar 2007 12:16:52 +0000 (12:16 +0000)
 (backport)

Misc/NEWS
Python/pythonrun.c

index aa1ffd8976d292ab4a41a880d15ecb01e9f0e7ec..3cefca9fcf059b2835b7e681d0e3edca01a88789 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
 Core and builtins
 -----------------
 
+- Bug #1674503: close the file opened by execfile() in an error condition.
+
 - Patch #1674228: when assigning a slice (old-style), check for the
   sq_ass_slice instead of the sq_slice slot.
 
index e83c4cb4233a49a68fdccada1e69abe703ad32c2..3b5307c7fb0a3281cf028b71ca6d7688d6ef6f42 100644 (file)
@@ -1244,12 +1244,12 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
        
        mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
                                   flags, NULL, arena);
+       if (closeit)
+               fclose(fp);
        if (mod == NULL) {
                PyArena_Free(arena);
                return NULL;
        }
-       if (closeit)
-               fclose(fp);
        ret = run_mod(mod, filename, globals, locals, flags, arena);
        PyArena_Free(arena);
        return ret;