Skip to content

Commit fe24ab9

Browse files
committed
[#8058] Close file handle before exec_file() routine returns.
1 parent a911c17 commit fe24ab9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/exec.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
9696
FILE *fs = PyFile_AsFile(file.get());
9797
#endif
9898

99-
PyObject* result = PyRun_File(fs,
99+
int closeit = 1; // Close file before PyRun returns
100+
PyObject* result = PyRun_FileEx(fs,
100101
f,
101102
Py_file_input,
102-
global.ptr(), local.ptr());
103+
global.ptr(), local.ptr(),
104+
closeit);
103105
if (!result) throw_error_already_set();
104106
return object(detail::new_reference(result));
105107
}

0 commit comments

Comments
 (0)