Return the ASCII system stream as unique_ptr to stop a per-load leak#159
Merged
Merged
Conversation
gSystemTextFileStream returned a heap-allocated std::ifstream*; callers only close()d it and never delete()d, leaking one std::ifstream per ASCII geometry/material load (and on the not-found / nullptr paths). The leak grows with geometry reloads, so long interactive sessions accumulate it. Return std::unique_ptr<std::ifstream> so ownership transfers to the caller and the stream is closed and freed on scope exit. The three return IN; sites move the same unique_ptr; return nullptr; constructs an empty one. Callers drop the now-redundant IN->close() (RAII handles it). Fixes gemc#132 Co-Authored-By: Claude Fable 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.
gSystemTextFileStreamreturned a heap-allocatedstd::ifstream*; callers onlyclose()d it and neverdeleted, leaking onestd::ifstreamper ASCII geometry/material load (and on the not-found /nullptrpaths). The leak grows with geometry reloads, so long interactive sessions accumulate it.Return
std::unique_ptr<std::ifstream>so ownership transfers to the caller and the stream is closed and freed on scope exit. The threereturn IN;sites move the same unique_ptr;return nullptr;constructs an empty one. Callers drop the now-redundantIN->close()(RAII handles it).Validation: the text factory and both callers compile clean (Geant4 11.4.1 dev container).
Fixes #132