From 0709fad052b399c3f8993f93246828ec5dad8379 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 17 May 2026 19:09:19 +0900 Subject: [PATCH] [3.13] gh-149921: Fix reference leaks in _interpchannels and _interpqueues modules (GH-149922) (cherry picked from commit acefff95eab3db6b7cf837f3ce2707bbf9199376) Co-authored-by: AN Long --- .../Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst | 2 ++ Modules/_interpchannelsmodule.c | 4 ++-- Modules/_interpqueuesmodule.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst diff --git a/Misc/NEWS.d/next/Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst b/Misc/NEWS.d/next/Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst new file mode 100644 index 00000000000000..113bd1a802f799 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst @@ -0,0 +1,2 @@ +Fix reference leaks in error paths of the :mod:`!_interpchannels` and +:mod:`!_interpqueues` extension modules. diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c index 460b4e5f4ea4f0..4d5099f380714e 100644 --- a/Modules/_interpchannelsmodule.c +++ b/Modules/_interpchannelsmodule.c @@ -2553,6 +2553,7 @@ _channelid_from_xid(_PyCrossInterpreterData *data) { struct _channelid_xid *xid = \ (struct _channelid_xid *)_PyCrossInterpreterData_DATA(data); + PyObject *cidobj = NULL; // It might not be imported yet, so we can't use _get_current_module(). PyObject *mod = PyImport_ImportModule(MODULE_NAME_STR); @@ -2562,11 +2563,10 @@ _channelid_from_xid(_PyCrossInterpreterData *data) assert(mod != Py_None); module_state *state = get_module_state(mod); if (state == NULL) { - return NULL; + goto done; } // Note that we do not preserve the "resolve" flag. - PyObject *cidobj = NULL; int err = newchannelid(state->ChannelIDType, xid->cid, xid->end, _global_channels(), 0, 0, (channelid **)&cidobj); diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c index d84b53d9021a53..7a89e2f13a1c72 100644 --- a/Modules/_interpqueuesmodule.c +++ b/Modules/_interpqueuesmodule.c @@ -1355,6 +1355,7 @@ _queueobj_from_xid(_PyCrossInterpreterData *data) // XXX import it? PyErr_SetString(PyExc_RuntimeError, MODULE_NAME_STR " module not imported yet"); + Py_DECREF(qidobj); return NULL; }