]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41336: Fix the error handling in zoneinfo_new_instance() (GH-21546)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Jul 2020 13:10:11 +0000 (06:10 -0700)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 13:10:11 +0000 (06:10 -0700)
Do not call PyObject_CallMethod() with a live exception (like
KeyboardInterrupt).
(cherry picked from commit eca2549f5a5048b44ca88b9555f1c62f094e3c12)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Modules/_zoneinfo.c

index 319d6c7b7760e2e52f244db9c7cfa1de1d584711..bee84cbf8f9f422f226979c5766c473bcb9e5c99 100644 (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);