Skip to content

test/common: fix memory leak in librados completion tests#63595

Merged
tchaikov merged 1 commit intoceph:mainfrom
tchaikov:wip-test_librados_completion-fix-leak
Jun 5, 2025
Merged

test/common: fix memory leak in librados completion tests#63595
tchaikov merged 1 commit intoceph:mainfrom
tchaikov:wip-test_librados_completion-fix-leak

Conversation

@tchaikov
Copy link
Contributor

@tchaikov tchaikov commented May 29, 2025

Replace raw pointers with unique_ptr for AioCompletion instances in test_librados_completion to prevent memory leaks. Previously, each test case allocated AioCompletion objects but never freed them, causing AddressSanitizer to report leaks.

The unique_ptr automatically manages the object lifecycle, ensuring cleanup when the pointer goes out of scope.

Fixes ASan error:

`==1199357==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x5602d9f0eaad in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_librados_completion+0x1f2aad) (BuildId: ef5b4b8f0a479e21b6a2686519ff4c3ef71b9f94)
    #1 0x7f3ac9b776f4 in librados::v14_2_0::Rados::aio_create_completion() /home/jenkins-build/build/workspace/ceph-pull-requests/src/librados/librados_cxx.cc:2892:10
    #2 0x5602d9f11a0a in CoroExcept_AioComplete_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/common/test_librados_completion.cc:54:14
    #3 0x5602da01d69d in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2653:10

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

Replace raw pointers with unique_ptr for AioCompletion instances in
test_librados_completion to prevent memory leaks. Previously, each test
case allocated AioCompletion objects but never freed them, causing
AddressSanitizer to report leaks.

The unique_ptr automatically manages the object lifecycle, ensuring
cleanup when the pointer goes out of scope.

Fixes ASan error:

```
`==1199357==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x5602d9f0eaad in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_librados_completion+0x1f2aad) (BuildId: ef5b4b8f0a479e21b6a2686519ff4c3ef71b9f94)
    #1 0x7f3ac9b776f4 in librados::v14_2_0::Rados::aio_create_completion() /home/jenkins-build/build/workspace/ceph-pull-requests/src/librados/librados_cxx.cc:2892:10
    #2 0x5602d9f11a0a in CoroExcept_AioComplete_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/common/test_librados_completion.cc:54:14
    #3 0x5602da01d69d in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2653:10
```

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@github-actions github-actions bot added the tests label May 29, 2025
@tchaikov tchaikov mentioned this pull request May 29, 2025
14 tasks
@cbodley cbodley requested a review from adamemerson May 29, 2025 15:10
@tchaikov
Copy link
Contributor Author

jenkins test make check

@tchaikov
Copy link
Contributor Author

tchaikov commented Jun 3, 2025

@adamemerson hi Adam, could you help review this change?

Copy link
Contributor

@adamemerson adamemerson left a comment

Choose a reason for hiding this comment

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

This is great! Thank you.

@tchaikov tchaikov merged commit cc19269 into ceph:main Jun 5, 2025
20 of 21 checks passed
@tchaikov tchaikov deleted the wip-test_librados_completion-fix-leak branch June 5, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants