Skip to content

Commit c6cc282

Browse files
[3.14] gh-134557: Suppress immortalization in _PyCode_GetScriptXIData under free-threading (gh134738)
Disable immortalization around Py_CompileString*(). The same approach as 332356b that fixed the refleaks in compile() and eval(). E: 09e72cf can pass test_capi, test_sys and test__interpchannels with this patch for me. (cherry picked from commit c60f39a, AKA gh-134686) Co-authored-by: neonene <[email protected]>
1 parent bc3d892 commit c6cc282

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)