Skip to content

Commit 3a7c5dd

Browse files
ZackerySpytzmiss-islington
authored andcommitted
bpo-41336: Fix the error handling in zoneinfo_new_instance() (pythonGH-21546)
Do not call PyObject_CallMethod() with a live exception (like KeyboardInterrupt). (cherry picked from commit eca2549) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 663f827 commit 3a7c5dd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Modules/_zoneinfo.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
224224
self = NULL;
225225
cleanup:
226226
if (file_obj != NULL) {
227+
PyObject *exc, *val, *tb;
228+
PyErr_Fetch(&exc, &val, &tb);
227229
PyObject *tmp = PyObject_CallMethod(file_obj, "close", NULL);
228-
Py_DECREF(tmp);
230+
_PyErr_ChainExceptions(exc, val, tb);
231+
if (tmp == NULL) {
232+
Py_CLEAR(self);
233+
}
234+
Py_XDECREF(tmp);
229235
Py_DECREF(file_obj);
230236
}
231237
Py_DECREF(file_path);

0 commit comments

Comments
 (0)