summaryrefslogtreecommitdiffstats
path: root/Modules/_zoneinfo.c
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-06-09 21:48:54 (GMT)
committerGitHub <noreply@github.com>2023-06-09 21:48:54 (GMT)
commit33c92c4f15539806c8aff8574ff30a8b307e3e4d (patch)
treee84eafcfc64ad4a79570f5a9a31e27cdac68c8eb /Modules/_zoneinfo.c
parent91441bf7cbaefbd328ee7efa59a06e661f61542e (diff)
downloadcpython-33c92c4f15539806c8aff8574ff30a8b307e3e4d.zip
cpython-33c92c4f15539806c8aff8574ff30a8b307e3e4d.tar.gz
cpython-33c92c4f15539806c8aff8574ff30a8b307e3e4d.tar.bz2
gh-105375: Improve error handling in `zoneinfo` module (#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>
Diffstat (limited to 'Modules/_zoneinfo.c')
-rw-r--r--Modules/_zoneinfo.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 0dcdb4d..0ced9d0 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;
}