Skip to content

Commit 122ac6c

Browse files
committed
gh-140306: Fix memory leaks in cross-interpreter data handling
1 parent d86ad87 commit 122ac6c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed
Lines changed: 2 additions & 0 deletions
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

Modules/_interpchannelsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ _channelitem_clear_data(_channelitem *item, int removed)
580580
{
581581
if (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);
584584
item->data = NULL;
585585
}
586586

Python/crossinterp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,8 @@ _release_xid_data(_PyXIData_t *xidata, int rawfree)
11531153
{
11541154
PyObject *exc = PyErr_GetRaisedException();
11551155
int res = rawfree
1156-
? _PyXIData_Release(xidata)
1157-
: _PyXIData_ReleaseAndRawFree(xidata);
1156+
? _PyXIData_ReleaseAndRawFree(xidata)
1157+
: _PyXIData_Release(xidata);
11581158
if (res < 0) {
11591159
/* The owning interpreter is already destroyed. */
11601160
_PyXIData_Clear(NULL, xidata);
@@ -1814,6 +1814,7 @@ _PyXI_InitFailure(_PyXI_failure *failure, _PyXI_errcode code, PyObject *obj)
18141814
const char *msg = _copy_string_obj_raw(msgobj, NULL);
18151815
Py_DECREF(msgobj);
18161816
if (PyErr_Occurred()) {
1817+
PyMem_RawFree((void *)msg);
18171818
return -1;
18181819
}
18191820
*failure = (_PyXI_failure){

0 commit comments

Comments
 (0)