Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Invalid Pointer Dereference due to std::vector auto-resizing in Memory Manager Result push_back #1939

Open
CncGpp opened this issue Feb 20, 2025 · 2 comments

Comments

@CncGpp
Copy link

CncGpp commented Feb 20, 2025

Describe the bug
When a Memory Manager class is registered, the results of each iteration are appended to an std::vector, and a pointer to the newly added element is used as a reference thereafter.

memory_results.push_back(MemoryManager::Result());
MemoryManager::Result* memory_result = &memory_results.back();

However, when the vector automatically resizes, these pointers become invalid, leading to corrupted statistical measurements.
The problem only occurs if the number of repetitions is greater than one.

To reproduce
Steps to reproduce the behavior:

  1. Register a Memory Manager class
  2. Run any benchmark with at least 3 repetitions
  3. User the Json reporter to see the corrupted memory related stats.

Expected behavior
Pointers to stored values should remain valid, or the implementation should ensure they are updated correctly when the vector reallocates.

Additional context
Possible fixes:

  • Use std::list or instead of std::vector to avoid reallocation issues.
  • Store indices instead of pointers if possible.
  • Reserve GetNumRepeats() values to the std::vector to ensure no automatic growth is performed.
@LebedevRI
Copy link
Collaborator

Please can you show the ASan output?

@LebedevRI
Copy link
Collaborator

Ah yes, CreateRunReport() is of course wrong.
BenchmarkReporter::Run should store MemoryManager::Result, not the pointer to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants