Bug #1674503: close the file opened by execfile() in an error condition.
diff --git a/Misc/NEWS b/Misc/NEWS
index 894f1cb..ed8cec4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@
 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 98ae115..3d0c68f 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1251,12 +1251,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;