https://github.com/python/cpython/commit/d7473f7a47673e3680fb5bf54730e1194c9853f1
commit: d7473f7a47673e3680fb5bf54730e1194c9853f1
branch: 3.13
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-10-20T10:13:15Z
summary:

[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 <[email protected]>

files:
A Misc/NEWS.d/next/Core and 
Builtins/2025-10-18-21-29-45.gh-issue-140306.xS5CcS.rst
M Modules/_interpchannelsmodule.c
M Modules/_interpqueuesmodule.c
M Python/crossinterp.c

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);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to