[3.12] gh-105375: Improve _decimal error handling (GH-105605) (#105647)

Fix a bug where an exception could end up being overwritten.
(cherry picked from commit c932f72849)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-11 03:55:18 -07:00 committed by GitHub
parent 36ecbc3570
commit b4b5565e47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -0,0 +1 @@
Fix bug in :mod:`decimal` where an exception could end up being overwritten.

View file

@ -3615,9 +3615,13 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
goto error;
}
Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp));
if (numerator == NULL) {
Py_DECREF(tmp);
goto error;
}
Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp));
Py_DECREF(tmp);
if (numerator == NULL || denominator == NULL) {
if (denominator == NULL) {
goto error;
}
}