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 eca2549f5a)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-07-20 06:10:11 -07:00 committed by GitHub
parent 663f827341
commit add7cfc4c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);