Fix default reporter use after free#2248
Open
devtejasx wants to merge 2 commits into
Open
Conversation
…2149) RunMemoryManager called memory_manager->Start() before allocating the internal ThreadManager and running the benchmark's Setup(), and called Stop() after resetting the ThreadManager and running Teardown(). As a result the MemoryManager attributed the library's own bookkeeping allocation and any per-benchmark fixture allocations to the benchmark, so the reported allocation count could never be accurate. Setup()/Teardown() already run outside the timed region; make memory measurement consistent by bracketing only RunInThread with Start()/ Stop(), and move the ThreadManager creation and Setup()/Teardown() outside that window. Add memory_manager_ordering_test, which registers a MemoryManager and asserts no Setup/Teardown occurs between Start() and Stop(). It fails on the previous ordering and passes with this change. Signed-off-by: devtejasx <tejasnagmote520@gmail.com>
CreateDefaultDisplayReporter() cached its reporter in a function-local static and returned that pointer. But the returned pointer is owned by the caller: RunSpecifiedBenchmarks() wraps it in a std::unique_ptr that frees it when the call returns. The first call therefore freed the static reporter, and the next call returned the same, now-dangling pointer, which was dereferenced when setting up the output streams -- a heap-use-after-free reachable by simply calling RunSpecifiedBenchmarks more than once (reported via fuzzing on the no-match filter path). Return a fresh, caller-owned reporter on every call. Add default_display_reporter_test, which holds two reporters from two calls alive at once and asserts they are distinct objects; it fails on the old static implementation and passes with this fix. Verified locally with g++ 15.2; benchmark_test and memory_manager_test still pass. Signed-off-by: devtejasx <tejasnagmote520@gmail.com>
Collaborator
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.
No description provided.