-
Notifications
You must be signed in to change notification settings - Fork 275
Fix free transform segfault #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This looks like an unnecessary overhead. Should the variable not be captured to avoid dangling pointers? Or maybe just reset the variable pointers in free methods and check this state in |
|
That seems like a lot more work. And at least Claude doesn't seem to enthusiastic. Regarding variable capture and release:
It seems like a lot of work will be needed. How do you feel about having this short-term solution and keeping the proper fix in mind for later? Otherwise, the bug will remain there for a lot longer, I don't have the bandwith. |
|
The model destructor could release the variables before freeing the model, but this is a conventional change. Simple fix would be to declare the transformed variables as freed by setting the stored variable pointer to |
…m and model deletion
|
What about now @DominikKamp ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request addresses issue #604, which involved segmentation faults when accessing freed memory through Python's __repr__ method after calling freeTransform() or when the Model is destroyed. The fix adds NULL pointer checks in the __repr__ methods and implements a tracking mechanism to invalidate pointers when objects are freed.
Changes:
- Added NULL pointer checks in
Variable.__repr__()andConstraint.__repr__()to return special strings for freed objects - Implemented tracking for constraints in
_modelconssdictionary (similar to existing_modelvarsfor variables) - Added pointer invalidation logic in
Model.__dealloc__()andModel.freeTransform()to set pointers to NULL before freeing
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_model.py | Added two test cases to verify that repr() works correctly on freed variables and constraints after freeTransform() and Model destruction |
| src/pyscipopt/scip.pxi | Implemented NULL checks in __repr__ methods, added _modelconss tracking, pointer invalidation in cleanup methods, and tracking in constraint/variable creation and retrieval methods |
| src/pyscipopt/scip.pxd | Added _modelconss field declaration to Model class |
| CHANGELOG.md | Added entry documenting the segfault fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
|
@DominikKamp can it be merged, then? |
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
|
Otherwise, this looks fine, probably |
This is a problem with a recent merge not being compatible with numpy 1.16. It's not really relevant (numpy 1.16 is 7 years old), and is actively being worked on in #1164 |
Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com>
Fix #604 , the oldest issue in the repo. Basically, after
freeTransform(), VsCode would try to access freed memory, via Python's__repr__. This fix caches the names of variables and constraints to prevent the problem.