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 00000000000000..2178c4960636cb --- /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 4bfefd65f17446..2b429a252a8ec2 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 5818066eebe49a..d84b53d9021a53 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 8382d8b95e071c..2f6324d300dee0 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);