From 738c6040f7a5fb902f70e6d285da6d782494eeaf Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 12 Nov 2020 13:07:31 -0800 Subject: [PATCH] fix memory leak in dns unittest --- ixwebsocket/IXDNSLookup.cpp | 5 +++++ ixwebsocket/IXDNSLookup.h | 2 ++ test/IXDNSLookupTest.cpp | 2 ++ 3 files changed, 9 insertions(+) diff --git a/ixwebsocket/IXDNSLookup.cpp b/ixwebsocket/IXDNSLookup.cpp index 09618704..938d75e3 100644 --- a/ixwebsocket/IXDNSLookup.cpp +++ b/ixwebsocket/IXDNSLookup.cpp @@ -68,6 +68,11 @@ namespace ix : resolveUnCancellable(errMsg, isCancellationRequested); } + void DNSLookup::release(struct addrinfo* addr) + { + freeaddrinfo(addr); + } + struct addrinfo* DNSLookup::resolveUnCancellable( std::string& errMsg, const CancellationRequest& isCancellationRequested) { diff --git a/ixwebsocket/IXDNSLookup.h b/ixwebsocket/IXDNSLookup.h index 754da263..fcdd103d 100644 --- a/ixwebsocket/IXDNSLookup.h +++ b/ixwebsocket/IXDNSLookup.h @@ -31,6 +31,8 @@ namespace ix const CancellationRequest& isCancellationRequested, bool cancellable = true); + void release(struct addrinfo* addr); + private: struct addrinfo* resolveCancellable(std::string& errMsg, const CancellationRequest& isCancellationRequested); diff --git a/test/IXDNSLookupTest.cpp b/test/IXDNSLookupTest.cpp index 31a7e0aa..ca1180ee 100644 --- a/test/IXDNSLookupTest.cpp +++ b/test/IXDNSLookupTest.cpp @@ -24,6 +24,8 @@ TEST_CASE("dns", "[net]") res = dnsLookup->resolve(errMsg, [] { return false; }); std::cerr << "Error message: " << errMsg << std::endl; REQUIRE(res != nullptr); + + dnsLookup->release(res); } SECTION("Test resolving a non-existing hostname")