Repository navigation
Return the ring with the basis from the test parser, so it cannot leak - #96
Merged
d-torrance merged 1 commit intoSep 25, 2026
Merged
Conversation
basisParseFromString read a ring and a basis from a string and returned only the basis: auto& ring = *p.first.release(); // todo: fix leak A Basis refers to its ring without owning it, so nothing owned the ring. That comment dates from bbb09cb in 2013. Two of its three callers, the IO.ideal and Ideal.readwrite tests, leaked the ring, and that was the whole of the suite's ASan leak report: 1216 bytes in 8 allocations. The third, Poly.lead, avoided the leak by taking ownership itself, through the const pointer getPolyRing() returns, and declared that owner after the basis, so the ring was destroyed before the basis that refers to it. It is now ringAndBasisFromString, returning both as pair<unique_ptr<PolyRing>, unique_ptr<Basis>>. The callers bind them with a structured binding, so the ring lives exactly as long as the basis and is destroyed after it, and Poly.lead drops its workaround. The suite now runs clean under ASan, with no leak report at all. The rename is deliberate. C++ names do not encode the return type, so changing only the return type would have kept the exported symbol mgb::basisParseFromString(std::string), and a binary built against the old header would still link, then read one pointer where two were written. With the old name gone, such a binary fails to load with an undefined symbol instead. Nothing outside this repository is known to call it: its only reverse dependency packaged in Ubuntu is Macaulay2, which does not, and a GitHub code search finds only copies of mathicgb. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
basisParseFromString, the test helper that parses a ring and a basis from astring, returned only the basis:
A
Basisrefers to its ring without owning it, so once theunique_ptrwasreleased nothing owned the ring. That
tododates frombbb09cbin 2013.IO.idealandIdeal.readwriteleaked the ring. That was the whole ofthe suite's ASan leak report:
1216 byte(s) leaked in 8 allocation(s).Poly.leadavoided the leak by taking ownership itself, through the constpointer
getPolyRing()returns -- and declared that owner after the basis,so the ring was destroyed before the basis that refers to it.
The fix
It is now
ringAndBasisFromString, returning both:std::pair<std::unique_ptr<PolyRing>, std::unique_ptr<Basis>> ringAndBasisFromString(std::string str);The three tests bind them with
auto [ring, I] = ..., so the ring lives exactlyas long as the basis and, since
std::pairdestroys its members in reverse, isdestroyed after it.
Poly.leaddrops its workaround.Why rename it, not just change its return type
C++ names do not encode the return type. Changing only the return type would
have kept the exported symbol
mgb::basisParseFromString(std::string), so abinary built against the old header would still link and then read one pointer
where two were written. With the old name gone, such a binary fails to load
with an undefined symbol instead.
io-util.hppis installed and the function is exported fromlibmathicgb.so,so this is an ABI change to note for the release. Nothing outside this
repository is known to call it: its only reverse dependency packaged in Ubuntu
is Macaulay2, which does not, and a GitHub code search finds only copies of
mathicgb.
Verification
master reports 1216 bytes in 8 allocations.
-Wall -Wextraraises nothing new in the changed files.No autotools
distcheckrun locally; the commit touches no build system and CIcovers it.
🤖 Generated with Claude Code