Remove static identity matrices in lago.cpp to avoid memory corruption in downstream tasks#2091
Merged
ProfFan merged 1 commit intoborglab:developfrom May 30, 2025
Conversation
Member
|
Thanks for debugging! Are there performance issues related to creating those identity matrices over and over? I know they are template expressions but the factors themselves don't take Eigen template expressions, so they get transcribed into actual memory. And then copied? So - maybe we can at least allocate const Matrix variables on the stack outside the loop? |
Collaborator
|
@BITVoyager Could you rebase on |
…n in downstream tasks
372e750 to
7d130f2
Compare
ProfFan
approved these changes
May 30, 2025
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I encountered a memory issue while rebuilding the repo
gpslamagainst the latest GTSAMdevelopbranch. There are some memory issues.GTSAM or Eigen is trying to free a pointer that was offset (ptr - 1) from an actual malloc'ed block. The free occurs after
main()exits, during static/global object cleanup:This points to the two removed lines in
lago.cpp, which are static Eigen matrices. Eigen stores metadata (like the original malloc pointer) just before the returned pointer. If that memory is improperly aligned, copied, or double-freed (as can happen with global destruction order issues),handmade_aligned_free()crashes. In order to avoid this issue, I removed the two static variables and directly used the type aliases in function calls.