Repository navigation
Fix memory leaks and bad frees - #180
Merged
xiaoyeli merged 5 commits intoOct 18, 2026
Merged
Conversation
When the factorization reported a singular matrix (info > 0) or only a memory estimate was requested (lwork == -1), ?gssvx returned without freeing the permuted matrix AC from sp_preorder() and, for SLU_NR input, the temporary column-oriented copy AA. ?gsisx had the same leaks for lwork == -1 and for info > 0 with PivotGrowth set, and additionally leaked the MC64 permutation for lwork == -1.
* ?gssvx with Fact = DOFACT or SamePattern computes new factors on every call, but the factors from the previous transpose option were never freed. * ?gssv always allocates the factors itself, but they were only freed when lwork == 0. * With a user-supplied work array (lwork > 0) only the L and U matrix stores of the final factorization were freed. Free the factors after every factorization; for lwork > 0 only the matrix stores, as the factors themselves are stored in work[].
With lwork > 0 (option -l), the factors are stored in the user's work array. After the first solve, ?linsolx2 nevertheless called Destroy_SuperNode_Matrix() and Destroy_CompCol_Matrix() for lwork >= 0, freeing pointers into work[] that were not obtained from malloc. Only destroy the factors when SuperLU allocated them (lwork == 0).
With lwork > 0 (option -l), the factors are stored in the user's work array, but the L and U matrix stores are still allocated by SuperLU. The ?linsolx* examples freed work[] but leaked the stores.
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.
Claude Code is amazing. I reworked the suggestions to follow SuperLU's style and make logical commits to have an easier review.