Fix ChObjectExplorer leaking every ChValue allocated by a search - #788
Open
DanNegrut wants to merge 1 commit into
Open
Fix ChObjectExplorer leaking every ChValue allocated by a search#788DanNegrut wants to merge 1 commit into
DanNegrut wants to merge 1 commit into
Conversation
ChObjectExplorer::ClearSearch() deletes the ChValue objects allocated by the
previous search, but the delete loop was placed after this->results.clear().
By the time the loop was reached, results.size() was already zero, so the loop
ran no iterations and deleted nothing.
ClearSearch() runs at the start of every search (via PrepareSearch) and again
from the destructor, so every ChValue ever allocated by out(), out_array_pre()
and out_ref() was leaked. A single FetchValues("*") over a container leaks one
ChValue per matched property, and the Irrlicht object tree in ChIrrGUI builds a
fresh explorer per node per frame, so the leak grows with runtime.
Moving the loop above results.clear() is the whole fix. The loop counter is
also changed from int to size_t to match results.size() and drop the
signed/unsigned comparison warning.
The pointers in results are owned by the explorer: they come from
new ChValueSpecific<>(...) in the out() overloads and from bVal.new_clone() in
out_array_pre() and out_ref(). Deleting them here is therefore correct, and no
caller retains them across a search boundary. Both in-tree consumers were
checked: demo_CH_archive.cpp reuses one explorer for several sequential
searches but consumes each result set before starting the next search, and
ChIrrGUI.cpp constructs a fresh explorer per call and per loop iteration,
including on its recursive path, so each instance performs exactly one search.
Reported in #779, which also covers a separate dangling-pointer defect in the
enum overload that is not addressed here.
Co-Authored-By: Claude Opus 5 (1M context) <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.
ChObjectExplorer::ClearSearch() deletes the ChValue objects allocated by the previous search, but the delete loop was placed after this->results.clear(). By the time the loop was reached, results.size() was already zero, so the loop ran no iterations and deleted nothing.
ClearSearch() runs at the start of every search (via PrepareSearch) and again from the destructor, so every ChValue ever allocated by out(), out_array_pre() and out_ref() was leaked. A single FetchValues("*") over a container leaks one ChValue per matched property, and the Irrlicht object tree in ChIrrGUI builds a fresh explorer per node per frame, so the leak grows with runtime.
Moving the loop above results.clear() is the whole fix. The loop counter is also changed from int to size_t to match results.size() and drop the signed/unsigned comparison warning.
The pointers in results are owned by the explorer: they come from new ChValueSpecific<>(...) in the out() overloads and from bVal.new_clone() in out_array_pre() and out_ref(). Deleting them here is therefore correct, and no caller retains them across a search boundary. Both in-tree consumers were checked: demo_CH_archive.cpp reuses one explorer for several sequential searches but consumes each result set before starting the next search, and ChIrrGUI.cpp constructs a fresh explorer per call and per loop iteration, including on its recursive path, so each instance performs exactly one search.
Reported in #779, which also covers a separate dangling-pointer defect in the enum overload that is not addressed here.