Free G4World's G4Volume wrappers; forbid copy/move to avoid double-free#167
Merged
Merged
Conversation
G4World stored raw G4Volume* wrappers in g4volumesMap but had no destructor, so every g4world.reset() on geometry reload leaked one wrapper per volume — unbounded growth in long interactive sessions. Add a destructor that deletes the wrappers (Geant4 owns the contained solid/logical/physical objects, so only the lightweight GEMC wrappers are freed). Because G4World previously inherited GBase's defaulted copy/move, adding an owning destructor would make a shallow copy double-free; G4World is only ever held by shared_ptr, so delete copy and move to forbid relocation. Verified the deletions don't break the build (nothing copies or moves G4World). Fixes gemc#135 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.
G4Worldstored rawG4Volume*wrappers ing4volumesMapbut had no destructor, so everyg4world.reset()on geometry reload leaked one wrapper per volume — unbounded growth in long interactive sessions (large SoLID-scale geometries reloaded many times).Add a destructor that deletes the wrappers — Geant4 owns the contained solid/logical/physical objects, so only the lightweight GEMC wrappers are freed. Because
G4Worldpreviously inherited GBase's defaulted copy/move, adding an owning destructor would make a shallow copy double-free;G4Worldis only ever held byshared_ptr, so this also deletes copy and move to forbid relocation (closing the same class of bug as #136).Validation: rebuilt
gemcin the Geant4 11.4.1 dev container — the deleted copy/move compile cleanly, confirming nothing copies or movesG4World.Fixes #135