[Python-checkins] bpo-37933: Fix faulthandler.cancel_dump_traceback_later() (GH-15440)

Victor Stinner webhook-mailer at python.org
Thu Aug 29 12:30:08 EDT 2019


https://github.com/python/cpython/commit/e278335a6eb049e6028db9a8dcb8baac6cb365ee
commit: e278335a6eb049e6028db9a8dcb8baac6cb365ee
branch: master
author: Thomas A Caswell <tcaswell at gmail.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019-08-29T18:30:04+02:00
summary:

bpo-37933: Fix faulthandler.cancel_dump_traceback_later() (GH-15440)

Fix faulthandler.cancel_dump_traceback_later() call
if cancel_dump_traceback_later() was not called previously.

files:
M Lib/test/test_faulthandler.py
M Modules/faulthandler.c

diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 1cf20db1c7ff..b1aa8c32284b 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -817,6 +817,17 @@ def test_disable_windows_exc_handler(self):
         self.assertEqual(output, [])
         self.assertEqual(exitcode, 0xC0000005)
 
+    def test_cancel_later_without_dump_traceback_later(self):
+        # bpo-37933: Calling cancel_dump_traceback_later()
+        # without dump_traceback_later() must not segfault.
+        code = dedent("""
+            import faulthandler
+            faulthandler.cancel_dump_traceback_later()
+        """)
+        output, exitcode = self.get_output(code)
+        self.assertEqual(output, [])
+        self.assertEqual(exitcode, 0)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 35e7b34c29cc..011ab5fa28f2 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -631,6 +631,11 @@ faulthandler_thread(void *unused)
 static void
 cancel_dump_traceback_later(void)
 {
+    /* If not scheduled, nothing to cancel */
+    if (!thread.cancel_event) {
+        return;
+    }
+
     /* Notify cancellation */
     PyThread_release_lock(thread.cancel_event);
 



More information about the Python-checkins mailing list