[Python-checkins] bpo-41336: Fix the error handling in zoneinfo_new_instance() (GH-21546)
Zackery Spytz
webhook-mailer at python.org
Mon Jul 20 08:51:33 EDT 2020
https://github.com/python/cpython/commit/eca2549f5a5048b44ca88b9555f1c62f094e3c12
commit: eca2549f5a5048b44ca88b9555f1c62f094e3c12
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-07-20T15:51:26+03:00
summary:
bpo-41336: Fix the error handling in zoneinfo_new_instance() (GH-21546)
Do not call PyObject_CallMethod() with a live exception (like
KeyboardInterrupt).
files:
M Modules/_zoneinfo.c
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 319d6c7b7760e..bee84cbf8f9f4 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -224,8 +224,14 @@ zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
self = NULL;
cleanup:
if (file_obj != NULL) {
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
PyObject *tmp = PyObject_CallMethod(file_obj, "close", NULL);
- Py_DECREF(tmp);
+ _PyErr_ChainExceptions(exc, val, tb);
+ if (tmp == NULL) {
+ Py_CLEAR(self);
+ }
+ Py_XDECREF(tmp);
Py_DECREF(file_obj);
}
Py_DECREF(file_path);
More information about the Python-checkins
mailing list