From 11312d0e59349fcd32ea9b40af12cb59e5cdb1e7 Mon Sep 17 00:00:00 2001 From: Rongqi Sun Date: Mon, 15 Apr 2024 09:04:14 +0000 Subject: [PATCH] common/dns_resolve: free res_ninit/res_nquery When sanitizer is enabled, unittest_osdscrub shows ``` ================================================================= ==1633952==ERROR: LeakSanitizer: detected memory leaks Direct leak of 28 byte(s) in 1 object(s) allocated from: #0 0xaaaab4e108e0 in malloc (/root/ceph/build/bin/unittest_osdscrub+0x1ed08e0) (BuildId: b3cfa2137be96d75535beecf0f2500cec10c7550) #1 0xffffa8cac2f8 in __res_context_send resolv/./resolv/res_send.c:334:9 #2 0xffffa8ca9c54 in __res_context_query resolv/./resolv/res_query.c:216:6 #3 0xffffa8caa4a8 in __res_context_querydomain resolv/./resolv/res_query.c:625:9 #4 0xffffa8caa4a8 in __res_context_search resolv/./resolv/res_query.c:381:9 #5 0xffffa8caaa20 in context_search_common resolv/./resolv/res_query.c:550:16 #6 0xffffa8caaa20 in res_nsearch resolv/./resolv/res_query.c:563:10 #7 0xffffabbf1f64 in ceph::ResolvHWrapper::res_nsearch(__res_state*, char const*, int, int, unsigned char*, int) /root/ceph/src/common/dns_resolve.cc:37:10 #8 0xffffabbf6574 in ceph::DNSResolver::resolve_srv_hosts(ceph::common::CephContext*, std::__cxx11::basic_string, std::allocator > const&, ceph::DNSResolver::SRV_Protocol, std::__cxx11::basic_string, std::allocator > const&, std::map, std::allocator >, ceph::DNSResolver::Record, std::less, std::allocator > >, std::allocator, std::allocator > const, ceph::DNSResolver::Record> > >*) /root/ceph/src/common/dns_resolve.cc:295:19 #9 0xffffac8edaf0 in MonMap::init_with_dns_srv(ceph::common::CephContext*, std::__cxx11::basic_string, std::allocator >, bool, std::ostream&) /root/ceph/src/mon/MonMap.cc:935:36 #10 0xffffac8eeec8 in MonMap::build_initial(ceph::common::CephContext*, bool, std::ostream&) /root/ceph/src/mon/MonMap.cc:1014:20 #11 0xffffac85beb0 in MonClient::build_initial_monmap() /root/ceph/src/mon/MonClient.cc:93:18 #12 0xaaaab4e50d98 in TestOSDScrub_scrub_time_permit_Test::TestBody() /root/ceph/src/test/osd/TestOSDScrub.cc:73:6 #13 0xaaaab4f655b0 in void testing::internal::HandleSehExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) /root/ceph/src/googletest/googletest/src/gtest.cc:2605:10 #14 0xaaaab4f16264 in void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) /root/ceph/src/googletest/googletest/src/gtest.cc:2641:14 #15 0xaaaab4ec6ca8 in testing::Test::Run() /root/ceph/src/googletest/googletest/src/gtest.cc:2680:5 #16 0xaaaab4ec8bec in testing::TestInfo::Run() /root/ceph/src/googletest/googletest/src/gtest.cc:2858:11 #17 0xaaaab4eca1ec in testing::TestSuite::Run() /root/ceph/src/googletest/googletest/src/gtest.cc:3012:28 #18 0xaaaab4ee5fb0 in testing::internal::UnitTestImpl::RunAllTests() /root/ceph/src/googletest/googletest/src/gtest.cc:5723:44 #19 0xaaaab4f6f4c4 in bool testing::internal::HandleSehExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /root/ceph/src/googletest/googletest/src/gtest.cc:2605:10 #20 0xaaaab4f1d4bc in bool testing::internal::HandleExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /root/ceph/src/googletest/googletest/src/gtest.cc:2641:14 #21 0xaaaab4ee5428 in testing::UnitTest::Run() /root/ceph/src/googletest/googletest/src/gtest.cc:5306:10 #22 0xaaaab4e4b790 in RUN_ALL_TESTS() /root/ceph/src/googletest/googletest/include/gtest/gtest.h:2486:46 #23 0xaaaab4e49dbc in main /root/ceph/src/test/unit.cc:45:10 #24 0xffffa8bc73f8 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #25 0xffffa8bc74c8 in __libc_start_main csu/../csu/libc-start.c:392:3 #26 0xaaaab4d9972c in _start (/root/ceph/build/bin/unittest_osdscrub+0x1e5972c) (BuildId: b3cfa2137be96d75535beecf0f2500cec10c7550) ----------------------------------------------------- Suppressions used: count bytes template 1 45 ^MallocExtension::Initialize ----------------------------------------------------- SUMMARY: AddressSanitizer: 28 byte(s) leaked in 1 allocation(s). ``` 1. 'res_ninit/res_nquery' memory should be freed. Signed-off-by: Rongqi Sun --- src/common/dns_resolve.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/dns_resolve.cc b/src/common/dns_resolve.cc index a44510d6deab3..435bcc657e403 100644 --- a/src/common/dns_resolve.cc +++ b/src/common/dns_resolve.cc @@ -56,6 +56,7 @@ DNSResolver::~DNSResolver() #ifdef HAVE_RES_NQUERY for (auto iter = states.begin(); iter != states.end(); ++iter) { struct __res_state *s = *iter; + res_nclose(s); delete s; } #endif