Skip to content

Commit

Permalink
pythongh-105375: Improve error handling in zoneinfo module (python#…
Browse files Browse the repository at this point in the history
…105586)

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

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
sobolevn and erlend-aasland committed Jun 9, 2023
1 parent 91441bf commit 33c92c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.
17 changes: 11 additions & 6 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,19 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
}
else {
PyObject *replace = PyObject_GetAttrString(tmp, "replace");
Py_DECREF(tmp);
if (replace == NULL) {
return NULL;
}
PyObject *args = PyTuple_New(0);
if (args == NULL) {
Py_DECREF(replace);
return NULL;
}
PyObject *kwargs = PyDict_New();

Py_DECREF(tmp);
if (args == NULL || kwargs == NULL || replace == NULL) {
Py_XDECREF(args);
Py_XDECREF(kwargs);
Py_XDECREF(replace);
if (kwargs == NULL) {
Py_DECREF(replace);
Py_DECREF(args);
return NULL;
}

Expand Down

0 comments on commit 33c92c4

Please sign in to comment.