Skip to content

Commit 0488451

Browse files
[3.13] gh-151126: Add missing PyErr_NoMemory in _winapi module (GH-151154) (#151182)
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 b032f3f commit 0488451

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
@@ -1184,8 +1184,10 @@ gethandlelist(PyObject *mapping, const char *name, Py_ssize_t *size)
11841184
}
11851185

11861186
ret = PyMem_Malloc(*size);
1187-
if (ret == NULL)
1187+
if (ret == NULL) {
1188+
PyErr_NoMemory();
11881189
goto cleanup;
1190+
}
11891191

11901192
for (i = 0; i < PySequence_Fast_GET_SIZE(value_fast); i++) {
11911193
ret[i] = PYNUM_TO_HANDLE(PySequence_Fast_GET_ITEM(value_fast, i));
@@ -1268,6 +1270,7 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
12681270
attribute_list->attribute_list = PyMem_Malloc(attribute_list_size);
12691271
if (attribute_list->attribute_list == NULL) {
12701272
ret = -1;
1273+
PyErr_NoMemory();
12711274
goto cleanup;
12721275
}
12731276

0 commit comments

Comments
 (0)