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.



This is a potential fix to #2848
It was AI generated by Google AI Studio
Here are it's workings:
Based on the Valgrind output and the provided code, the memory leak is located in the
TransactionAnchoredVariablesclass (which is part of theTransactionobject).The stack trace indicates that memory allocated during the construction of
AnchoredSetVariableTranslationProxy(specifically inside astd::functioninitialization) is never freed.In
src/transaction.cc, theTransactionconstructor initializesTransactionAnchoredVariables:And in
src/variables/variable.h, the code accessesm_variableArgsNamesas if it were an object (using&), not a pointer:This usage pattern combined with the leak indicates that
TransactionAnchoredVariablesdeclares its members (likem_variableArgsNames) as references (&) but initializes them usingnewin its constructor.Because they are references, the
TransactionAnchoredVariablesdestructor does not (and cannot) delete the objects they refer to. Consequently, theAnchoredSetVariableTranslationProxyobjects (and their internalstd::functionmembers) are leaked when theTransactionis destroyed.To fix this:
The members in
TransactionAnchoredVariablesshould be changed from references (e.g.,AnchoredSetVariableTranslationProxy &) to pointers (e.g.,std::unique_ptr<AnchoredSetVariableTranslationProxy>), or they should be deleted manually in theTransactionAnchoredVariablesdestructor if raw pointers are used. Given the&t->memberusage, they were likely intended to be value members or references binding to dynamic memory (which is the bug).