Skip to content

Commit bbcd28e

Browse files
authored
[3.14] gh-151126: Fix missing memory errors in _interpchannelsmodule.c (GH-151239) (#151336)
(cherry picked from commit 9fd1a12)
1 parent 58c6e78 commit bbcd28e

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a crash, when there's no memory left on a device,
2+
which happened in :mod:`!_interpchannels` module.
3+
4+
Now it raises proper :exc:`MemoryError` errors.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a crash, when there's no memory left on a device, which happened in
2+
:mod:`!_interpchannels` module.
3+
4+
Now it raises proper :exc:`MemoryError` errors.

Modules/_interpchannelsmodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ static _channelends *
921921
_channelends_new(void)
922922
{
923923
_channelends *ends = GLOBAL_MALLOC(_channelends);
924-
if (ends== NULL) {
924+
if (ends == NULL) {
925+
PyErr_NoMemory();
925926
return NULL;
926927
}
927928
ends->numsendopen = 0;
@@ -1115,6 +1116,7 @@ _channel_new(PyThread_type_lock mutex, struct _channeldefaults defaults)
11151116
assert(check_unbound(defaults.unboundop));
11161117
_channel_state *chan = GLOBAL_MALLOC(_channel_state);
11171118
if (chan == NULL) {
1119+
PyErr_NoMemory();
11181120
return NULL;
11191121
}
11201122
chan->mutex = mutex;
@@ -1313,6 +1315,7 @@ _channelref_new(int64_t cid, _channel_state *chan)
13131315
{
13141316
_channelref *ref = GLOBAL_MALLOC(_channelref);
13151317
if (ref == NULL) {
1318+
PyErr_NoMemory();
13161319
return NULL;
13171320
}
13181321
ref->cid = cid;
@@ -1698,6 +1701,7 @@ _channel_set_closing(_channelref *ref, PyThread_type_lock mutex) {
16981701
}
16991702
chan->closing = GLOBAL_MALLOC(struct _channel_closing);
17001703
if (chan->closing == NULL) {
1704+
PyErr_NoMemory();
17011705
goto done;
17021706
}
17031707
chan->closing->ref = ref;

0 commit comments

Comments
 (0)