Fix memory leak in overlapping relocation test functions (#7184)#7187
Open
GitMasterJatin wants to merge 1 commit intoTheHPXProject:masterfrom
Open
Fix memory leak in overlapping relocation test functions (#7184)#7187GitMasterJatin wants to merge 1 commit intoTheHPXProject:masterfrom
GitMasterJatin wants to merge 1 commit intoTheHPXProject:masterfrom
Conversation
…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
Up to standards ✅🟢 Issues
|
|
Can one of the admins verify this patch? |
Contributor
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. |
hkaiser
reviewed
Apr 14, 2026
| HPX_TEST(T::made.size() == N); | ||
|
|
||
| return ptr; | ||
| } |
Contributor
There was a problem hiding this comment.
Could we avoid the duplication by moving this into a separate header file to be included by all tests, please?
Contributor
|
@GitMasterJatin please pay attention to the CIs, e.g., the clang-format issues reported. |
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.
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.