From 27eb87b7992191c93087535d140560f3e84c3d1f Mon Sep 17 00:00:00 2001 From: Rongqi Sun Date: Wed, 22 May 2024 06:47:50 +0000 Subject: [PATCH] test/rbd: free remote_journaler in PrepareRemoteImageRequest tests When sanitizer is enabled, unittest_rbd_mirror shows ``` ================================================================= ==1377627==ERROR: LeakSanitizer: detected memory leaks Direct leak of 2 byte(s) in 2 object(s) allocated from: #0 0xaaaac462d088 in operator new(unsigned long) (/root/ceph/build/bin/unittest_rbd_mirror+0x30cd088) (BuildId: 054d3b6699c622daad91c7f70e36616220fbd5ad) #1 0xaaaac522f13c in rbd::mirror::image_replayer::PrepareRemoteImageRequest::get_client() /root/ceph/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc:148:24 #2 0xaaaac522e60c in rbd::mirror::image_replayer::PrepareRemoteImageRequest::handle_get_mirror_info(int) /root/ceph/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc:120:5 #3 0xaaaac5232d1c in librbd::util::detail::C_CallbackAdapter, &(rbd::mirror::image_replayer::PrepareRemoteImageRequest::handle_get_mirror_info(int))>::finish(int) /root/ceph/src/librbd/Utils.h:63:5 #4 0xaaaac4863428 in Context::complete(int) /root/ceph/src/include/Context.h:99:5 #5 0xaaaac489ac30 in librbd::asio::ContextWQ::queue(Context*, int)::'lambda'()::operator()() const /root/ceph/src/librbd/asio/ContextWQ.h:31:12 #6 0xaaaac489aaf4 in boost::asio::detail::binder0::operator()() /root/ceph/build/boost/include/boost/asio/detail/bind_handler.hpp:60:5 #7 0xaaaac489aaac in void boost::asio::asio_handler_invoke >(boost::asio::detail::binder0&, ...) /root/ceph/build/boost/include/boost/asio/handler_invoke_hook.hpp:88:3 #8 0xaaaac489aa4c in void boost_asio_handler_invoke_helpers::invoke, librbd::asio::ContextWQ::queue(Context*, int)::'lambda'()>(boost::asio::detail::binder0&, librbd::asio::ContextWQ::queue(Context*, int)::'lambda'()&) /root/ceph/build/boost/include/boost/asio/detail/handler_invoke_helpers.hpp:54:3 #9 0xaaaac489a9ec in void boost::asio::detail::asio_handler_invoke, librbd::asio::ContextWQ::queue(Context*, int)::'lambda'()>(boost::asio::detail::binder0&, boost::asio::detail::binder0*) /root/ceph/build/boost/include/boost/asio/detail/bind_handler.hpp:111:3 #10 0xaaaac4899c00 in void boost_asio_handler_invoke_helpers::invoke, boost::asio::detail::binder0 >(boost::asio::detail::binder0&, boost::asio::detail::binder0&) /root/ceph/build/boost/include/boost/asio/detail/handler_invoke_helpers.hpp:54:3 #11 0xaaaac489c814 in boost::asio::detail::executor_op, std::allocator, boost::asio::detail::scheduler_operation>::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned long) /root/ceph/build/boost/include/boost/asio/detail/executor_op.hpp:71:7 #12 0xaaaac489fb4c in boost::asio::detail::scheduler_operation::complete(void*, boost::system::error_code const&, unsigned long) /root/ceph/build/boost/include/boost/asio/detail/scheduler_operation.hpp:40:5 #13 0xaaaac489f074 in boost::asio::detail::strand_executor_service::run_ready_handlers(std::shared_ptr&) /root/ceph/build/boost/include/boost/asio/detail/impl/strand_executor_service.ipp:150:8 #14 0xaaaac489ed2c in boost::asio::detail::strand_executor_service::invoker, 0ul> const, void>::operator()() /root/ceph/build/boost/include/boost/asio/detail/impl/strand_executor_service.hpp:136:5 #15 0xaaaac489ebd4 in void boost::asio::asio_handler_invoke, 0ul> const, void> >(boost::asio::detail::strand_executor_service::invoker, 0ul> const, void>&, ...) /root/ceph/build/boost/include/boost/asio/handler_invoke_hook.hpp:88:3 #16 0xaaaac489e284 in void boost_asio_handler_invoke_helpers::invoke, 0ul> const, void>, boost::asio::detail::strand_executor_service::invoker, 0ul> const, void> >(boost::asio::detail::strand_executor_service::invoker, 0ul> const, void>&, boost::asio::detail::strand_executor_service::invoker, 0ul> const, void>&) /root/ceph/build/boost/include/boost/asio/detail/handler_invoke_helpers.hpp:54:3 #17 0xaaaac48a3e08 in boost::asio::detail::executor_op, 0ul> const, void>, std::allocator, boost::asio::detail::scheduler_operation>::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned long) /root/ceph/build/boost/include/boost/asio/detail/executor_op.hpp:71:7 #18 0xaaaac489fb4c in boost::asio::detail::scheduler_operation::complete(void*, boost::system::error_code const&, unsigned long) /root/ceph/build/boost/include/boost/asio/detail/scheduler_operation.hpp:40:5 #19 0xaaaac6766b1c in boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock&, boost::asio::detail::scheduler_thread_info&, boost::system::error_code const&) /root/ceph/build/boost/include/boost/asio/detail/impl/scheduler.ipp:493:12 #20 0xaaaac67660a4 in boost::asio::detail::scheduler::run(boost::system::error_code&) /root/ceph/build/boost/include/boost/asio/detail/impl/scheduler.ipp:210:10 #21 0xaaaac7562d48 in boost::asio::io_context::run() /root/ceph/build/boost/include/boost/asio/impl/io_context.ipp:64:24 #22 0xaaaac7562bcc in ceph::async::io_context_pool::start(short)::'lambda'()::operator()() const /root/ceph/src/common/async/context_pool.h:69:16 #23 0xaaaac7562b18 in void std::__invoke_impl(std::__invoke_other, ceph::async::io_context_pool::start(short)::'lambda'()&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14 #24 0xaaaac7562960 in std::__invoke_result::type std::__invoke(ceph::async::io_context_pool::start(short)::'lambda'()&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:96:14 #25 0xaaaac7562804 in std::invoke_result::type std::invoke(ceph::async::io_context_pool::start(short)::'lambda'()&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/functional:97:14 #26 0xaaaac75627dc in auto std::thread make_named_thread(std::basic_string_view >, ceph::async::io_context_pool::start(short)::'lambda'()&&)::'lambda'(ceph::async::io_context_pool::start(short)::'lambda'()&&)::operator()(ceph::async::io_context_pool::start(short)::'lambda'()&&) const /root/ceph/src/common/Thread.h:79:10 #27 0xaaaac7562728 in ceph::async::io_context_pool::start(short)::'lambda'() std::__invoke_impl(std::basic_string_view >, ceph::async::io_context_pool::start(short)::'lambda'()&&)::'lambda'(ceph::async::io_context_pool::start(short)::'lambda'()&&), ceph::async::io_context_pool::start(short)::'lambda'()>(std::__invoke_other, std::thread make_named_thread(std::basic_string_view >, ceph::async::io_context_pool::start(short)::'lambda'()&&)::'lambda'(ceph::async::io_context_pool::start(short)::'lambda'()&&)&&, ceph::async::io_context_pool::start(short)::'lambda'()&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14 #28 0xaaaac75624ec in std::__invoke_result::type std::__invoke(std::basic_string_view >, ceph::async::io_context_pool::start(short)::'lambda'()&&)::'lambda'(ceph::async::io_context_pool::start(short)::'lambda'()&&), ceph::async::io_context_pool::start(short)::'lambda'()>(ceph::async::io_context_pool::start(short)::'lambda'()&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:96:14 #29 0xaaaac756231c in void std::thread::_Invoker(std::basic_string_view >, ceph::async::io_context_pool::start(short)::'lambda'()&&)::'lambda'(ceph::async::io_context_pool::start(short)::'lambda'()&&), ceph::async::io_context_pool::start(short)::'lambda'()> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/std_thread.h:259:13 SUMMARY: AddressSanitizer: 2 byte(s) leaked in 2 allocation(s). ``` Signed-off-by: Rongqi Sun --- .../image_replayer/test_mock_PrepareRemoteImageRequest.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc index e5b473c0f07c7..d522222dfa966 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc @@ -328,6 +328,8 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessJournal) { ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr); ASSERT_EQ(cls::journal::CLIENT_STATE_DISCONNECTED, mock_journal_state_builder.remote_client_state); + // owned by StateBuilder, normally freed in StateBuilder::close() + delete mock_journal_state_builder.remote_journaler; } TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessSnapshot) { @@ -431,6 +433,8 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) { ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr); ASSERT_EQ(cls::journal::CLIENT_STATE_CONNECTED, mock_journal_state_builder.remote_client_state); + // owned by StateBuilder, normally freed in StateBuilder::close() + delete mock_journal_state_builder.remote_journaler; } TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, GetMirrorImageIdError) {