[SATYR PATCH] python: fix reference counts for crash_thread

Martin Milata mmilata at redhat.com
Wed Aug 28 09:59:43 UTC 2013


Fixes #101.

Signed-off-by: Martin Milata <mmilata at redhat.com>
---
 python/py_base_stacktrace.c | 3 ++-
 tests/python/core.py        | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/python/py_base_stacktrace.c b/python/py_base_stacktrace.c
index e9bf484..8a8c6f0 100644
--- a/python/py_base_stacktrace.c
+++ b/python/py_base_stacktrace.c
@@ -356,6 +356,7 @@ sr_py_multi_stacktrace_get_bthash(PyObject *self, PyObject *args)
 PyObject *
 sr_py_single_stacktrace_get_crash(PyObject *self, void *unused)
 {
+    Py_INCREF(self);
     return self;
 }
 
@@ -403,7 +404,7 @@ sr_py_multi_stacktrace_get_crash(PyObject *self, void *unused)
         struct sr_py_base_thread *thread = (struct sr_py_base_thread *)item;
         if (thread->thread == crash_thread)
         {
-            /* TODO incref? */
+            Py_INCREF(item);
             return item;
         }
     }
diff --git a/tests/python/core.py b/tests/python/core.py
index cb880ae..96f4ffd 100755
--- a/tests/python/core.py
+++ b/tests/python/core.py
@@ -55,6 +55,14 @@ class TestCoreStacktrace(BindingsTestCase):
     def test_crash_thread(self):
         self.assertTrue(self.trace.crash_thread is self.trace.threads[1])
 
+    def test_crash_thread_refcount(self):
+        c = self.trace.crash_thread
+        del c
+        c = self.trace.crash_thread
+        del c
+        # segfault in revision 6f91aba95397e56c665c420f574d73adb64df832
+        f = self.trace.crash_thread.frames[0]
+
     def test_from_json(self):
         trace = satyr.CoreStacktrace.from_json('{}')
         self.assertEqual(trace.threads, [])
-- 
1.8.3.1



More information about the Crash-catcher mailing list