[3.11] gh-105375: Improve error handling in zoneinfo module (GH-105586) (#105613)

Fix bugs where exceptions could end up being overwritten
because of deferred error handling.

(cherry picked from commit 33c92c4f15)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-09 15:54:00 -07:00 committed by GitHub
parent 6cb1308005
commit 4ceb5c4924
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -0,0 +1 @@
Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.

View file

@ -581,14 +581,19 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
}
else {
PyObject *replace = PyObject_GetAttrString(tmp, "replace");
PyObject *args = PyTuple_New(0);
PyObject *kwargs = PyDict_New();
Py_DECREF(tmp);
if (args == NULL || kwargs == NULL || replace == NULL) {
Py_XDECREF(args);
Py_XDECREF(kwargs);
Py_XDECREF(replace);
if (replace == NULL) {
return NULL;
}
PyObject *args = PyTuple_New(0);
if (args == NULL) {
Py_DECREF(replace);
return NULL;
}
PyObject *kwargs = PyDict_New();
if (kwargs == NULL) {
Py_DECREF(replace);
Py_DECREF(args);
return NULL;
}