[3.11] gh-105375: Improve _decimal error handling (GH-105605) (#105648)

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:58:56 -07:00 committed by GitHub
parent cfa0f7c59b
commit cb26fafdcc
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

@ -3658,9 +3658,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;
}
}