From 53583e3e567982230ea890e0195e8a13e7f03be2 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 10 Jun 2026 18:59:11 +0300 Subject: [PATCH] [3.13] gh-151126: Fix missing memory errors in `_interpchannelsmodule.c` (GH-151239) (cherry picked from commit 9fd1a125bc0ebdc26eae684da6e48ef24ee23b34) Co-authored-by: sobolevn --- .../2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst | 4 ++++ Modules/_interpchannelsmodule.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst new file mode 100644 index 00000000000000..c91939dbe559cd --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst @@ -0,0 +1,4 @@ +Fix a crash, when there's no memory left on a device, +which happened in :mod:`!_interpchannels` module. + +Now it raises proper :exc:`MemoryError` errors. diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c index 4d5099f380714e..82aaea3b97bb5c 100644 --- a/Modules/_interpchannelsmodule.c +++ b/Modules/_interpchannelsmodule.c @@ -903,7 +903,8 @@ static _channelends * _channelends_new(void) { _channelends *ends = GLOBAL_MALLOC(_channelends); - if (ends== NULL) { + if (ends == NULL) { + PyErr_NoMemory(); return NULL; } ends->numsendopen = 0; @@ -1095,6 +1096,7 @@ _channel_new(PyThread_type_lock mutex, int unboundop) { _channel_state *chan = GLOBAL_MALLOC(_channel_state); if (chan == NULL) { + PyErr_NoMemory(); return NULL; } chan->mutex = mutex; @@ -1295,6 +1297,7 @@ _channelref_new(int64_t cid, _channel_state *chan) { _channelref *ref = GLOBAL_MALLOC(_channelref); if (ref == NULL) { + PyErr_NoMemory(); return NULL; } ref->cid = cid; @@ -1680,6 +1683,7 @@ _channel_set_closing(_channelref *ref, PyThread_type_lock mutex) { } chan->closing = GLOBAL_MALLOC(struct _channel_closing); if (chan->closing == NULL) { + PyErr_NoMemory(); goto done; } chan->closing->ref = ref;