https://github.com/python/cpython/commit/acefff95eab3db6b7cf837f3ce2707bbf9199376
commit: acefff95eab3db6b7cf837f3ce2707bbf9199376
branch: main
author: AN Long <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-05-17T13:09:19+03:00
summary:

gh-149921: Fix reference leaks in _interpchannels and _interpqueues modules 
(#149922)

files:
A Misc/NEWS.d/next/Library/2026-05-16-21-08-33.gh-issue-149921.I1yNML.rst
M Modules/_interpchannelsmodule.c
M Modules/_interpqueuesmodule.c

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 3c356cb40d2bca..c6d107d243dda0 100644
--- a/Modules/_interpchannelsmodule.c
+++ b/Modules/_interpchannelsmodule.c
@@ -2586,6 +2586,7 @@ static PyObject *
 _channelid_from_xid(_PyXIData_t *data)
 {
     struct _channelid_xid *xid = (struct _channelid_xid *)_PyXIData_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);
@@ -2595,11 +2596,10 @@ _channelid_from_xid(_PyXIData_t *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 777b6854749884..b23aa5f39489d9 100644
--- a/Modules/_interpqueuesmodule.c
+++ b/Modules/_interpqueuesmodule.c
@@ -1363,6 +1363,7 @@ _queueobj_from_xid(_PyXIData_t *data)
     if (mod == NULL) {
         mod = PyImport_ImportModule(MODULE_NAME_STR);
         if (mod == NULL) {
+            Py_DECREF(qidobj);
             return NULL;
         }
     }

_______________________________________________
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