summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-09 22:54:00 (GMT)
committerGitHub <noreply@github.com>2023-06-09 22:54:00 (GMT)
commit4ceb5c4924f8a63ddb45aac001565bb36cf94c1e (patch)
tree5faf1b79e865ea870d288d9f30e43fc69959107d /Modules
parent6cb130800554d2582d0e0f63246aa5f16d91e26b (diff)
downloadcpython-4ceb5c4924f8a63ddb45aac001565bb36cf94c1e.zip
cpython-4ceb5c4924f8a63ddb45aac001565bb36cf94c1e.tar.gz
cpython-4ceb5c4924f8a63ddb45aac001565bb36cf94c1e.tar.bz2
[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 33c92c4f15539806c8aff8574ff30a8b307e3e4d) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_zoneinfo.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 55975f4..5f584ff 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -581,14 +581,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;
}