[lldb/swig] Fix ref counting issue in SBProcess::GetScriptedImplementation
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Fri, 3 Mar 2023 20:35:42 +0000 (12:35 -0800)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Sat, 4 Mar 2023 03:33:02 +0000 (19:33 -0800)
When using SBProcess::GetScriptedImplementation in python, if the
process has a valid implementation, we returned a reference of the
object without incrementing the reference counting. That causes the
interpreter to crash after accessing the reference several times.

This patch address this by incrementing the reference count when passing
the valid object reference.

Differential Revision: https://reviews.llvm.org/D145260

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
lldb/bindings/python/python-typemaps.swig
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

index 2057aa6..1b1f2e1 100644 (file)
@@ -61,6 +61,8 @@
   if (!$result) {
     $result = Py_None;
     Py_INCREF(Py_None);
+  } else {
+    Py_INCREF($result);
   }
 }
 
index 5a198cc..b5a14a9 100644 (file)
@@ -80,6 +80,15 @@ class ScriptedProcesTestCase(TestBase):
         self.assertEqual(process.GetProcessID(), 666)
         self.assertEqual(process.GetNumThreads(), 0)
 
+        impl = process.GetScriptedImplementation()
+        self.assertTrue(impl)
+        impl = process.GetScriptedImplementation()
+        self.assertTrue(impl)
+        impl = process.GetScriptedImplementation()
+        self.assertTrue(impl)
+        impl = process.GetScriptedImplementation()
+        self.assertTrue(impl)
+
         addr = 0x500000000
         buff = process.ReadMemory(addr, 4, error)
         self.assertEqual(buff, None)