Skip to content

Commit a060d43

Browse files
Hajo Kirchhoffstefanseefeld
authored andcommitted
-fix: boost::python::exec_file completely broken when PY_VERSION_HEX >= 0x03010000. Bug: char* f pointed to a temporary buffer returned by PyBytes_AsString. This buffer was released when Py_DECREF(fb) was called. As a result, f pointed to invalid memory when being passed to Py_RunFile.
1 parent 8dd1511 commit a060d43

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/exec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ object BOOST_PYTHON_DECL exec_file(char const *filename, object global, object l
109109
PyObject *fo = Py_BuildValue("s", f);
110110
PyObject *fb = Py_None;
111111
PyUnicode_FSConverter(fo, &fb);
112-
f = PyBytes_AsString(fb);
113-
FILE *fs = fopen(f, "r");
112+
char *f_as_uft = PyBytes_AsString(fb);
113+
FILE *fs = fopen(f_as_uft, "r");
114114
Py_DECREF(fo);
115115
Py_DECREF(fb);
116116
#elif PY_VERSION_HEX >= 0x03000000

0 commit comments

Comments
 (0)