]> granicus.if.org Git - python/commitdiff
bpo-37933: Fix faulthandler.cancel_dump_traceback_later() (GH-15440)
authorThomas A Caswell <tcaswell@gmail.com>
Thu, 29 Aug 2019 16:30:04 +0000 (12:30 -0400)
committerVictor Stinner <vstinner@redhat.com>
Thu, 29 Aug 2019 16:30:04 +0000 (18:30 +0200)
Fix faulthandler.cancel_dump_traceback_later() call
if cancel_dump_traceback_later() was not called previously.

Lib/test/test_faulthandler.py
Modules/faulthandler.c

index 1cf20db1c7ff5c3e7c3b74fe11dd5405d4cb430b..b1aa8c32284ba3996c40e20d0c8990485540c352 100644 (file)
@@ -817,6 +817,17 @@ class FaultHandlerTests(unittest.TestCase):
         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()
index 35e7b34c29ccd5d2fecf30afe4966ffe7c1a1de3..011ab5fa28f256185415e726ea41396fc755e831 100644 (file)
@@ -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);