[3.11] gh-106350: Tkinter: do not ignore return value of `mp_init()` (GH-106351) (GH-107259)

(cherry picked from commit b5ae7c4984)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
This commit is contained in:
Miss Islington (bot) 2023-07-26 00:58:07 -07:00 committed by GitHub
parent 9fa44d7a30
commit 36208b5f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Detect possible memory allocation failure in the libtommath function :c:func:`mp_init`
used by the ``_tkinter`` module.

View File

@ -906,8 +906,9 @@ asBignumObj(PyObject *value)
return NULL;
}
hexchars += neg + 2; /* skip sign and "0x" */
mp_init(&bigValue);
if (mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) {
if (mp_init(&bigValue) != MP_OKAY ||
mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY)
{
mp_clear(&bigValue);
Py_DECREF(hexstr);
PyErr_NoMemory();