summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst1
-rw-r--r--Modules/_zoneinfo.c17
2 files changed, 12 insertions, 6 deletions
diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst
new file mode 100644
index 0000000..4202b75
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst
@@ -0,0 +1 @@
+Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index c8c791b..38b806c 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -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;
}