Skip to content

Commit 489d6af

Browse files
[3.15] gh-151126: Add missing PyErr_NoMemory in _winapi module (GH-151154) (#151180)
gh-151126: Add missing `PyErr_NoMemory` in `_winapi` module (GH-151154) (cherry picked from commit 8d94fa7) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 2aba3d9 commit 489d6af

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Fix a crash, when there's no memory left on a device,
2-
which happened in code compilation.
3-
Now it raises a proper :exc:`MemoryError`.
2+
which happened in:
3+
4+
- code compilation
5+
- :func:`!_winapi.CreateProcess`
6+
7+
Now these places raise proper :exc:`MemoryError` errors.

Modules/_winapi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,10 @@ gethandlelist(PyObject *mapping, const char *name, Py_ssize_t *size)
11871187
}
11881188

11891189
ret = PyMem_Malloc(*size);
1190-
if (ret == NULL)
1190+
if (ret == NULL) {
1191+
PyErr_NoMemory();
11911192
goto cleanup;
1193+
}
11921194

11931195
for (i = 0; i < PySequence_Fast_GET_SIZE(value_fast); i++) {
11941196
ret[i] = PYNUM_TO_HANDLE(PySequence_Fast_GET_ITEM(value_fast, i));
@@ -1271,6 +1273,7 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
12711273
attribute_list->attribute_list = PyMem_Malloc(attribute_list_size);
12721274
if (attribute_list->attribute_list == NULL) {
12731275
ret = -1;
1276+
PyErr_NoMemory();
12741277
goto cleanup;
12751278
}
12761279

0 commit comments

Comments
 (0)