diff --git a/.build_number b/.build_number index 7b222bc4f..6afcd4b0c 100644 --- a/.build_number +++ b/.build_number @@ -1 +1 @@ -1593 +1594 diff --git a/src/libtriton/bindings/python/objects/pyTritonContext.cpp b/src/libtriton/bindings/python/objects/pyTritonContext.cpp index f6dbf2c0d..ea7c42d55 100644 --- a/src/libtriton/bindings/python/objects/pyTritonContext.cpp +++ b/src/libtriton/bindings/python/objects/pyTritonContext.cpp @@ -503,10 +503,12 @@ namespace triton { if (PyMethod_Check(function)) { cb_self = PyMethod_GET_SELF(function); cb = PyMethod_GET_FUNCTION(function); + Py_INCREF(cb_self); } else { cb = function; } + Py_INCREF(cb); try { switch (static_cast(PyLong_AsUint32(mode))) { @@ -2624,6 +2626,11 @@ namespace triton { return PyErr_Format(PyExc_TypeError, "%s", e.what()); } + Py_DECREF(cb); + if (cb_self != nullptr) { + Py_DECREF(cb_self); + } + Py_INCREF(Py_None); return Py_None; } diff --git a/src/testers/unittests/test_github_issues.py b/src/testers/unittests/test_github_issues.py index ac742298c..c5f40dcd3 100644 --- a/src/testers/unittests/test_github_issues.py +++ b/src/testers/unittests/test_github_issues.py @@ -649,6 +649,7 @@ def test_2(self): x0 = self.ctx.getConcreteRegisterValue(self.ctx.registers.x0) self.assertEqual(x0, 0x55667788) + class TestIssue1310(unittest.TestCase): """Testing #1310.""" @@ -700,3 +701,16 @@ def test_2(self): self.assertEqual(ctx.getConcreteRegisterValue(ctx.registers.tpidr_el0), 0x1122334455667788) self.assertEqual(ctx.getConcreteRegisterValue(ctx.registers.x20), 0x1122334455667788) + + +class TestIssue1035(unittest.TestCase): + def setup_callback(self, ctx): + def getMem(triton_ctx, memacc): + self.x = 1234 + ctx.addCallback(CALLBACK.GET_CONCRETE_MEMORY_VALUE, getMem) + + def test_1(self): + ctx = TritonContext(ARCH.X86_64) + self.setup_callback(ctx) + ctx.getConcreteMemoryAreaValue(0x1000, 0x1) + self.assertEqual(self.x, 1234)