Skip to content

Fix memory leak in overlapping relocation test functions (#7184)#7187

Open
GitMasterJatin wants to merge 1 commit intoTheHPXProject:masterfrom
GitMasterJatin:fix/relocation-test-memory-leak
Open

Fix memory leak in overlapping relocation test functions (#7184)#7187
GitMasterJatin wants to merge 1 commit intoTheHPXProject:masterfrom
GitMasterJatin:fix/relocation-test-memory-leak

Conversation

@GitMasterJatin
Copy link
Copy Markdown
Contributor

Summary

Fixes #7184

The setup<T>() helper in relocation test files allocates two buffers (mem1, mem2) and returns them as std::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, leaking N * 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:

  • The unnecessary second allocation
  • The silent memory leak
  • The misleading discarded binding pattern

Affected files (6 files, 20 leak sites fixed):

File Leak sites
uninitialized_relocate.cpp 4 (test_overlapping x 3, test_right_overlapping x 1)
uninitialized_relocaten.cpp 4 (test_overlapping x 3, test_right_overlapping x 1)
uninitialized_relocate_backward.cpp 3 (test_overlapping x 3)
uninitialized_relocate_sender.cpp 3 (test_overlapping x 3)
uninitialized_relocaten_sender.cpp 3 (test_overlapping x 3)
uninitialized_relocate_backward_sender.cpp 3 (test_overlapping x 3)

Testing

Built and ran all 3 available relocation test targets locally (macOS, Apple Clang, Debug build):

$ ./bin/uninitialized_relocate_test --hpx:threads=2          # EXIT_CODE=0
$ ./bin/uninitialized_relocaten_test --hpx:threads=2         # EXIT_CODE=0
$ ./bin/uninitialized_relocate_backward_test --hpx:threads=2 # EXIT_CODE=0

All tests pass. The sender test targets were not available in this build configuration but the changes are structurally identical.

…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
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@StellarBot
Copy link
Copy Markdown

Can one of the admins verify this patch?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of setup<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.

HPX_TEST(T::made.size() == N);

return ptr;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid the duplication by moving this into a separate header file to be included by all tests, please?

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Apr 14, 2026

@GitMasterJatin please pay attention to the CIs, e.g., the clang-format issues reported.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in overlapping relocation test functions

4 participants