This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][PR python/21460] Avoid segfault during Python cleanup


Rationale for the patch and repro instructions are explained in the bug.

I don't have any copyright assignment on file but this really should be trivial enough to avoid that, I think.

gdb/Changelog:
2017-05-25  paul cannon  <paul@thepaul.org>

	python/21460
	* python.c (gdbpy_set_quit_flag) Check Py_IsInitialized() before calling PyErr_SetInterrupt(), as Python may be shutting down already.

---
 gdb/python/python.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/python/python.c b/gdb/python/python.c
index be92f36..c6a8c17 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -247,7 +247,10 @@ gdbpy_enter::~gdbpy_enter ()
 static void
 gdbpy_set_quit_flag (const struct extension_language_defn *extlang)
 {
-  PyErr_SetInterrupt ();
+  if (Py_IsInitialized ())
+    {
+      PyErr_SetInterrupt ();
+    }
 }
 
 /* Return true if the quit flag has been set, false otherwise.  */
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]