Fix memory leak in overlapping relocation test functions (#7184)#7187
Conversation
Up to standards ✅🟢 Issues
|
|
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak in overlapping relocation test blocks by eliminating an unnecessary second allocation from the shared test setup helper.
Changes:
- Added a
setup_single<T>()helper that allocates/initializes only one buffer for overlapping relocation tests. - Updated overlapping and right-overlapping test blocks to use
setup_single<T>()instead ofsetup<T>()(which allocates two buffers).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocate.cpp | Adds setup_single and updates overlapping/right-overlapping tests to use it, removing the leaked second buffer. |
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocaten.cpp | Adds setup_single and updates overlapping/right-overlapping tests to use it, removing the leaked second buffer. |
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocate_backward.cpp | Adds setup_single and updates overlapping tests to use it, removing the leaked second buffer. |
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocate_sender.cpp | Adds setup_single and updates overlapping sender tests to use it, removing the leaked second buffer. |
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocaten_sender.cpp | Adds setup_single and updates overlapping sender tests to use it, removing the leaked second buffer. |
| libs/core/algorithms/tests/unit/algorithms/uninitialized_relocate_backward_sender.cpp | Adds setup_single and updates overlapping sender tests to use it, removing the leaked second buffer. |
|
@GitMasterJatin please pay attention to the CIs, e.g., the clang-format issues reported. |
…ct#7184) The setup<T>() helper allocates two buffers (mem1, mem2), but overlapping test blocks only use one buffer for in-place relocation. The second buffer was captured as a discarded binding (___) and never freed, leaking N * sizeof(T) bytes per overlapping test block. This commit introduces a setup_single<T>() helper that allocates only one buffer, and updates all overlapping test blocks across 6 files to use it: - uninitialized_relocate.cpp (4 sites) - uninitialized_relocaten.cpp (4 sites) - uninitialized_relocate_backward.cpp (3 sites) - uninitialized_relocate_sender.cpp (3 sites) - uninitialized_relocaten_sender.cpp (3 sites) - uninitialized_relocate_backward_sender.cpp (3 sites) Closes TheHPXProject#7184
45a2f56 to
dd6b670
Compare
Done Sir moved all shared test infrastructure (counted_struct, type aliases, clear(), setup(), and setup_single()) into a new header uninitialized_relocate_test_utils.hpp that is included by all 6 test files. Also fixed the clang-format violations. Force-pushed in dd6b670 |
|
@GitMasterJatin unfortunately, inspect is still not happy: |
The inspect tool flagged 4 Unicode EN DASH (U+2013) characters in the section-divider comments of uninitialized_relocate_test_utils.hpp. Replace all occurrences with plain ASCII hyphens to satisfy the non-ASCII character check.
setup() calls std::fill but <algorithm> was not directly included. The .cpp files no longer include <random>, so std::fill can no longer rely on transitive includes to pull in <algorithm>.
Thank you Sir |
Summary
Fixes #7184
The
setup<T>()helper in relocation test files allocates two buffers (mem1,mem2) and returns them asstd::pair<T*, T*>. Non-overlapping tests correctly free both, but overlapping tests only use one buffer for in-place relocation — the second buffer was captured as a discarded binding (___) and never freed, leakingN * sizeof(T)bytes per overlapping test block.Changes
Introduced a
setup_single<T>()helper that allocates only a single buffer for overlapping tests, then updated all overlapping test blocks to use it. This eliminates:Affected files (6 files, 20 leak sites fixed):
uninitialized_relocate.cpptest_overlappingx 3,test_right_overlappingx 1)uninitialized_relocaten.cpptest_overlappingx 3,test_right_overlappingx 1)uninitialized_relocate_backward.cpptest_overlappingx 3)uninitialized_relocate_sender.cpptest_overlappingx 3)uninitialized_relocaten_sender.cpptest_overlappingx 3)uninitialized_relocate_backward_sender.cpptest_overlappingx 3)Testing
Built and ran all 3 available relocation test targets locally (macOS, Apple Clang, Debug build):
All tests pass. The sender test targets were not available in this build configuration but the changes are structurally identical.