File tree
Misc/NEWS.d/next/Core_and_Builtins
Modules
Python
Original file line numberDiff line numberDiff line change@@ -0,0 +1,2 @@
1+Fix memory leaks in cross-interpreter channel operations and shared
2+namespace handling.
Original file line numberDiff line numberDiff line change@@ -580,7 +580,7 @@ _channelitem_clear_data(_channelitem *item, int removed)
580580{
581581if (item->data!=NULL) {
582582// It was allocated in channel_send().
583- (void)_release_xid_data(item->data, XID_IGNORE_EXC&XID_FREE);
583+ (void)_release_xid_data(item->data, XID_IGNORE_EXC|XID_FREE);
584584item->data=NULL;
585585 }
586586Original file line numberDiff line numberDiff line change@@ -436,7 +436,7 @@ _queueitem_clear_data(_queueitem *item)
436436return;
437437 }
438438// It was allocated in queue_put().
439- (void)_release_xid_data(item->data, XID_IGNORE_EXC&XID_FREE);
439+ (void)_release_xid_data(item->data, XID_IGNORE_EXC|XID_FREE);
440440item->data=NULL;
441441}
442442Original file line numberDiff line numberDiff line change@@ -1153,8 +1153,8 @@ _release_xid_data(_PyXIData_t *xidata, int rawfree)
11531153{
11541154PyObject*exc=PyErr_GetRaisedException();
11551155intres=rawfree
1156- ? _PyXIData_Release(xidata)
1157- : _PyXIData_ReleaseAndRawFree(xidata);
1156+ ? _PyXIData_ReleaseAndRawFree(xidata)
1157+ : _PyXIData_Release(xidata);
11581158if (res<0) {
11591159/* The owning interpreter is already destroyed. */
11601160_PyXIData_Clear(NULL, xidata);
@@ -1805,6 +1805,15 @@ _PyXI_InitFailureUTF8(_PyXI_failure *failure,
18051805int
18061806_PyXI_InitFailure(_PyXI_failure*failure, _PyXI_errcodecode, PyObject*obj)
18071807{
1808+*failure= (_PyXI_failure){
1809+ .code=code,
1810+ .msg=NULL,
1811+ .msg_owned=0,
1812+ };
1813+if (obj==NULL) {
1814+return0;
1815+ }
1816+18081817PyObject*msgobj=PyObject_Str(obj);
18091818if (msgobj==NULL) {
18101819return-1;
@@ -1813,7 +1822,7 @@ _PyXI_InitFailure(_PyXI_failure *failure, _PyXI_errcode code, PyObject *obj)
18131822// That happens automatically in _capture_current_exception().
18141823constchar*msg=_copy_string_obj_raw(msgobj, NULL);
18151824Py_DECREF(msgobj);
1816-if (PyErr_Occurred()) {
1825+if (msg==NULL) {
18171826return-1;
18181827 }
18191828*failure= (_PyXI_failure){