gh-151126: Add missing PyErr_NoMemory in _winapi module (#151154)

This commit is contained in:
sobolevn 2026-06-09 19:42:08 +03:00 committed by GitHub
parent 0fa06f4d7f
commit 8d94fa7b86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Fix a crash, when there's no memory left on a device,
which happened in code compilation.
Now it raises a proper :exc:`MemoryError`.
which happened in:
- code compilation
- :func:`!_winapi.CreateProcess`
Now these places raise proper :exc:`MemoryError` errors.

View file

@ -1194,8 +1194,10 @@ gethandlelist(PyObject *mapping, const char *name, Py_ssize_t *size)
}
ret = PyMem_Malloc(*size);
if (ret == NULL)
if (ret == NULL) {
PyErr_NoMemory();
goto cleanup;
}
for (i = 0; i < PySequence_Fast_GET_SIZE(value_fast); i++) {
ret[i] = PYNUM_TO_HANDLE(PySequence_Fast_GET_ITEM(value_fast, i));
@ -1278,6 +1280,7 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
attribute_list->attribute_list = PyMem_Malloc(attribute_list_size);
if (attribute_list->attribute_list == NULL) {
ret = -1;
PyErr_NoMemory();
goto cleanup;
}