Skip to content

Commit 4ceb5c4

Browse files
miss-islingtonsobolevnerlend-aasland
authored
[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 33c92c4) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 6cb1308 commit 4ceb5c4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.

Modules/_zoneinfo.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,19 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
581581
}
582582
else {
583583
PyObject *replace = PyObject_GetAttrString(tmp, "replace");
584+
Py_DECREF(tmp);
585+
if (replace == NULL) {
586+
return NULL;
587+
}
584588
PyObject *args = PyTuple_New(0);
589+
if (args == NULL) {
590+
Py_DECREF(replace);
591+
return NULL;
592+
}
585593
PyObject *kwargs = PyDict_New();
586-
587-
Py_DECREF(tmp);
588-
if (args == NULL || kwargs == NULL || replace == NULL) {
589-
Py_XDECREF(args);
590-
Py_XDECREF(kwargs);
591-
Py_XDECREF(replace);
594+
if (kwargs == NULL) {
595+
Py_DECREF(replace);
596+
Py_DECREF(args);
592597
return NULL;
593598
}
594599

0 commit comments

Comments
 (0)