From 15e138a0dc9a8e405cd9be260c2dd12aeb3f4aea Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 6 Mar 2007 12:16:52 +0000 Subject: [PATCH] Bug #1674503: close the file opened by execfile() in an error condition. (backport) --- Misc/NEWS | 2 ++ Python/pythonrun.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index aa1ffd8976d..3cefca9fcf0 100644 --- 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. diff --git a/Python/pythonrun.c b/Python/pythonrun.c index e83c4cb4233..3b5307c7fb0 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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;