Closed Nudelmeister closed 3 weeks ago
Thanks a lot for the report and the suggested fix! I think I like the solution of making ScipPtr
count the given references as it gives more freedom for russcip and would allow for more ergonomic use. I will work on it as soon as I can :)
A (zero-cost) alternative is to add a lifetime parameter. That would be API breaking and less ergonomic, but variable lifetimes seems to be the root cause of the problem.
So the signature of Solution
would become:
Solution<'a>
But I might be missing some intricacies of the libreary
Fixed in #149
From looking over the russcip code the cause seems obvious.
ScipPtr
's drop impl is responsible for cleaning up and freeing, butSolution
also holds the same raw pointer toScip
, causing a use after free.My first thought for a fix would be to remove the pointer aliasing, only
ScipPtr
should hold the pointer toScip
.ScipPtr
could then be reference counted. Alternatively, change the API so that it more closely mimics that of scip and require passing theScipPtr
separately.