From 450dd5704b0a2c96a3d69e483281c19a4eb1f202 Mon Sep 17 00:00:00 2001 From: "xunyi.lh" Date: Fri, 22 Dec 2023 17:09:58 +0800 Subject: [PATCH] Fix unittest for default resovler --- net/test/test.cpp | 4 ++-- net/utils.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/net/test/test.cpp b/net/test/test.cpp index a61d6f72..ad182a06 100644 --- a/net/test/test.cpp +++ b/net/test/test.cpp @@ -714,9 +714,9 @@ TEST(utils, resolver) { DEFER(delete resolver); net::IPAddr localhost("127.0.0.1"); net::IPAddr addr = resolver->resolve("localhost"); - EXPECT_EQ(localhost.to_nl(), addr.to_nl()); + if (addr.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr.to_nl()); auto func = [&](net::IPAddr addr_){ - EXPECT_EQ(localhost.to_nl(), addr_.to_nl()); + if (addr_.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr_.to_nl()); }; resolver->resolve("localhost", func); resolver->discard_cache("non-exist-host.com"); diff --git a/net/utils.cpp b/net/utils.cpp index efbe1bac..27890079 100644 --- a/net/utils.cpp +++ b/net/utils.cpp @@ -260,7 +260,12 @@ class DefaultResolver : public Resolver { public: DefaultResolver(uint64_t cache_ttl, uint64_t resolve_timeout) : dnscache_(cache_ttl), resolve_timeout_(resolve_timeout) {} - ~DefaultResolver() { dnscache_.clear(); } + ~DefaultResolver() { + for (auto it : dnscache_) { + ((IPAddrList*)it->_obj)->delete_all(); + } + dnscache_.clear(); + } IPAddr resolve(const char *host) override { auto ctr = [&]() -> IPAddrList* {