[3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140357)

(cherry picked from commit f9323213c9)

Co-authored-by: Shamil <ashm.tech@proton.me>
This commit is contained in:
Serhiy Storchaka 2025-10-20 13:13:15 +03:00 committed by GitHub
parent e5ebcabc6b
commit d7473f7a47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 4 deletions

View file

@ -0,0 +1,2 @@
Fix memory leaks in cross-interpreter channel operations and shared
namespace handling.

View file

@ -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;
}

View file

@ -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;
}

View file

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