8000 Disable immortalization around Py_CompileString*() · python/cpython@4dac776 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4dac776

Browse files
authored
Disable immortalization around Py_CompileString*()
1 parent cf8941c commit 4dac776

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Python/crossinterp.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,15 @@ get_script_xidata(PyThreadState *tstate, PyObject *obj, int pure,
908908
}
909909
goto error;
910910
}
911+
#ifdef Py_GIL_DISABLED
912+
// Don't immortalize code constants to avoid memory leaks.
913+
((_PyThreadStateImpl *)tstate)->suppress_co_const_immortalization++;
914+
#endif
911915
code = Py_CompileStringExFlags(
912916
script, filename, Py_file_input, &cf, optimize);
917+
#ifdef Py_GIL_DISABLED
918+
((_PyThreadStateImpl *)tstate)->suppress_co_const_immortalization--;
919+
#endif
913920
Py_XDECREF(ref);
914921
if (code == NULL) {
915922
goto error;

0 commit comments

Comments
 (0)
0