]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
test/common: fix memory leak in librados completion tests
authorKefu Chai <tchaikov@gmail.com>
Thu, 29 May 2025 12:39:54 +0000 (20:39 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 29 May 2025 15:00:49 +0000 (23:00 +0800)
commita98d8e6b36cd015272eb973faf4109a1f46d5eb0
tree48bcbb0d185820763f9b5aa4c01e873da5642164
parent7c89819f00f43f41763e3b9a433ae38fbdb7f42a
test/common: fix memory leak in librados completion tests

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>
src/test/common/test_librados_completion.cc