diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-07-20 13:10:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 13:10:11 (GMT) |
commit | add7cfc4c63f2ce2e8649906e6c8d902e95d8701 (patch) | |
tree | ca8ff25ac5fd684883fb6189628fbc8150bd5191 | |
parent | 663f827341caa272be7c3dce6156f1a76f5cc64d (diff) | |
download | cpython-add7cfc4c63f2ce2e8649906e6c8d902e95d8701.zip cpython-add7cfc4c63f2ce2e8649906e6c8d902e95d8701.tar.gz cpython-add7cfc4c63f2ce2e8649906e6c8d902e95d8701.tar.bz2 |
bpo-41336: Fix the error handling in zoneinfo_new_instance() (GH-21546)
Do not call PyObject_CallMethod() with a live exception (like
KeyboardInterrupt).
(cherry picked from commit eca2549f5a5048b44ca88b9555f1c62f094e3c12)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
-rw-r--r-- | Modules/_zoneinfo.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 319d6c7..bee84cb 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -224,8 +224,14 @@ error: 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); |