JonathanSalwan / Triton

Triton is a dynamic binary analysis library. Build your own program analysis tools, automate your reverse engineering, perform software verification or just emulate code.
https://triton-library.github.io
Apache License 2.0
3.39k stars 524 forks source link

Fix addCallback binding #1322

Closed cnheitman closed 1 month ago

cnheitman commented 1 month ago

Fix PR fixes a small memory leak in the addCallback function. This issue was spotted than to LIEF and their new nanobind implementation of its Python bindings (ref here).

JonathanSalwan commented 1 month ago

Mmmh, I remember adding these INC_REF due to a bad counting. I think that's why unit tests segfault =/

cnheitman commented 1 month ago

I'm checking the tests to understand better what's going on.

JonathanSalwan commented 1 month ago

Here is the commit that added these INC. Maybe it can help you. https://github.com/JonathanSalwan/Triton/commit/23f5c21db414513194ace26358b386fc409e24bb

cnheitman commented 1 month ago

I updated the PR. Now tests pass (at least locally), and I'm not getting the nanobind leak messages when using Triton with LIEF v0.14.1. It does not seem necessary to increase the refs in addCallback as the are "borrowed" refs and, in a similar way, they don't need to be decreased in removeCallback.

Let's wait until all tests run and see what happens.