From: Serhiy Storchaka Date: Mon, 20 Oct 2025 10:13:15 +0000 (+0300) Subject: [3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7473f7a47673e3680fb5bf54730e1194c9853f1;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140357) (cherry picked from commit f9323213c98c9f1f7f3bf5af883b73047432fe50) Co-authored-by: Shamil --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2025-10-18-21-29-45.gh-issue-140306.xS5CcS.rst b/Misc/NEWS.d/next/Core and Builtins/2025-10-18-21-29-45.gh-issue-140306.xS5CcS.rst new file mode 100644 index 000000000000..2178c4960636 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2025-10-18-21-29-45.gh-issue-140306.xS5CcS.rst @@ -0,0 +1,2 @@ +Fix memory leaks in cross-interpreter channel operations and shared +namespace handling. diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c index 4bfefd65f174..2b429a252a8e 100644 --- a/Modules/_interpchannelsmodule.c +++ b/Modules/_interpchannelsmodule.c @@ -562,7 +562,7 @@ _channelitem_clear_data(_channelitem *item, int removed) { if (item->data != NULL) { // It was allocated in channel_send(). - (void)_release_xid_data(item->data, XID_IGNORE_EXC & XID_FREE); + (void)_release_xid_data(item->data, XID_IGNORE_EXC | XID_FREE); item->data = NULL; } diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c index 5818066eebe4..d84b53d9021a 100644 --- a/Modules/_interpqueuesmodule.c +++ b/Modules/_interpqueuesmodule.c @@ -435,7 +435,7 @@ _queueitem_clear_data(_queueitem *item) return; } // It was allocated in queue_put(). - (void)_release_xid_data(item->data, XID_IGNORE_EXC & XID_FREE); + (void)_release_xid_data(item->data, XID_IGNORE_EXC | XID_FREE); item->data = NULL; } diff --git a/Python/crossinterp.c b/Python/crossinterp.c index 8382d8b95e07..2f6324d300de 100644 --- a/Python/crossinterp.c +++ b/Python/crossinterp.c @@ -455,8 +455,8 @@ _release_xid_data(_PyCrossInterpreterData *data, int rawfree) { PyObject *exc = PyErr_GetRaisedException(); int res = rawfree - ? _PyCrossInterpreterData_Release(data) - : _PyCrossInterpreterData_ReleaseAndRawFree(data); + ? _PyCrossInterpreterData_ReleaseAndRawFree(data) + : _PyCrossInterpreterData_Release(data); if (res < 0) { /* The owning interpreter is already destroyed. */ _PyCrossInterpreterData_Clear(NULL, data);