From aa5ed69a2957406428f87061f049a7654700ce61 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Thu, 18 Jun 2026 17:43:11 +0800 Subject: [PATCH 1/6] Fix missing memory errors in _interpqueuesmodule.c --- .../2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst | 3 +++ Modules/_interpqueuesmodule.c | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst new file mode 100644 index 000000000000000..6714451b45fb1ff --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst @@ -0,0 +1,3 @@ +Fix crashes when interpreter queues run out of memory while being listed or +shared between interpreters. These cases now raise a proper +:exc:`MemoryError`. diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c index 9979cd3457e1014..c900c0256efc18d 100644 --- a/Modules/_interpqueuesmodule.c +++ b/Modules/_interpqueuesmodule.c @@ -1045,6 +1045,7 @@ _queues_list_all(_queues *queues, int64_t *p_count) struct queue_id_and_info *ids = PyMem_NEW(struct queue_id_and_info, (Py_ssize_t)(queues->count)); if (ids == NULL) { + PyErr_NoMemory(); goto done; } _queueref *ref = queues->head; @@ -1328,6 +1329,7 @@ _queueid_xid_new(int64_t qid) struct _queueid_xid *data = PyMem_RawMalloc(sizeof(struct _queueid_xid)); if (data == NULL) { _queues_decref(queues, qid); + PyErr_NoMemory(); return NULL; } data->qid = qid; From 250808bc6353c20fc61fa542b762534976c13a77 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Thu, 25 Jun 2026 18:12:39 +0800 Subject: [PATCH 2/6] Update _interpqueuesmodule.c --- Modules/_interpqueuesmodule.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c index c900c0256efc18d..9b4a94f5f7915f5 100644 --- a/Modules/_interpqueuesmodule.c +++ b/Modules/_interpqueuesmodule.c @@ -1042,7 +1042,7 @@ _queues_list_all(_queues *queues, int64_t *p_count) { struct queue_id_and_info *qids = NULL; PyThread_acquire_lock(queues->mutex, WAIT_LOCK); - struct queue_id_and_info *ids = PyMem_NEW(struct queue_id_and_info, + struct queue_id_and_info *ids = PyMem_New(struct queue_id_and_info, (Py_ssize_t)(queues->count)); if (ids == NULL) { PyErr_NoMemory(); @@ -1322,7 +1322,14 @@ static void * _queueid_xid_new(int64_t qid) { _queues *queues = _get_global_queues(); - if (_queues_incref(queues, qid) < 0) { + int err = _queues_incref(queues, qid); + if (err < 0) { + PyObject *mod = PyImport_ImportModule(MODULE_NAME_STR); + if (mod == NULL) { + return NULL; + } + (void)handle_queue_error(err, mod, qid); + Py_DECREF(mod); return NULL; } From d44c06128b14dbbdca7b3328a3e26db5fb458741 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Thu, 25 Jun 2026 19:34:04 +0800 Subject: [PATCH 3/6] Address review comments --- Modules/_interpqueuesmodule.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c index 9b4a94f5f7915f5..db2ecd19e9c3d0a 100644 --- a/Modules/_interpqueuesmodule.c +++ b/Modules/_interpqueuesmodule.c @@ -1324,8 +1324,13 @@ _queueid_xid_new(int64_t qid) _queues *queues = _get_global_queues(); int err = _queues_incref(queues, qid); if (err < 0) { - PyObject *mod = PyImport_ImportModule(MODULE_NAME_STR); + assert(err == ERR_QUEUE_NOT_FOUND); + PyObject *mod = _get_current_module(); if (mod == NULL) { + if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_SystemError, + "missing " MODULE_NAME_STR " module"); + } return NULL; } (void)handle_queue_error(err, mod, qid); From 18bcd817a27dc61525cca6d4532591d4d3d69aed Mon Sep 17 00:00:00 2001 From: Pengyu Lee Date: Wed, 9 Sep 2026 11:53:30 +0800 Subject: [PATCH 4/6] updates NEWS --- .../2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst index 6714451b45fb1ff..cc888f302a167ab 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst @@ -1,3 +1,3 @@ -Fix crashes when interpreter queues run out of memory while being listed or -shared between interpreters. These cases now raise a proper -:exc:`MemoryError`. +Fix missing error handling in interpreter queues when listing queues or sharing a queue between interpreters. Memory allocation failures now raise +:exc:`MemoryError` instead of returning without an exception set. + From 29656c25f9b14e5e790099c0a93074f4d86d3064 Mon Sep 17 00:00:00 2001 From: Pengyu Lee Date: Wed, 9 Sep 2026 11:54:44 +0800 Subject: [PATCH 5/6] UP --- .../2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst index cc888f302a167ab..4bcec4d40c74b72 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst @@ -1,3 +1,3 @@ -Fix missing error handling in interpreter queues when listing queues or sharing a queue between interpreters. Memory allocation failures now raise -:exc:`MemoryError` instead of returning without an exception set. +Fix missing error handling in interpreter queues when listing queues or sharing a queue between interpreters. +Memory allocation failures now raise :exc:`MemoryError` instead of returning without an exception set. From 1ad99bb6ea60d09795a52004712dd6a5c3ba6430 Mon Sep 17 00:00:00 2001 From: Pengyu Lee Date: Wed, 9 Sep 2026 13:43:23 +0800 Subject: [PATCH 6/6] up --- .../2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst index 4bcec4d40c74b72..750c8d87b7f205b 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-18-17-31-02.gh-issue-151126.HubUYi.rst @@ -1,3 +1,2 @@ -Fix missing error handling in interpreter queues when listing queues or sharing a queue between interpreters. +Fix missing error handling in interpreter queues when listing queues or sharing a queue between interpreters. Memory allocation failures now raise :exc:`MemoryError` instead of returning without an exception set. -