Bug #1674503: close the file opened by execfile() in an error condition.
(backport)
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index e83c4cb..3b5307c 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1244,12 +1244,12 @@
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;