From 82a4d111ba8f1a70389754002d923266583d4f8b Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Thu, 6 Jul 2017 14:40:45 +0100 Subject: [PATCH] test: use ares_free_string() throughout As pointed out by Gisle Vanem in #125. --- test/ares-test-internal.cc | 10 +++++----- test/ares-test-misc.cc | 4 ++-- test/ares-test.cc | 2 +- test/dns-proto.cc | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/ares-test-internal.cc b/test/ares-test-internal.cc index ff9cb5d2..a5ea258b 100644 --- a/test/ares-test-internal.cc +++ b/test/ares-test-internal.cc @@ -190,7 +190,7 @@ TEST(LibraryInit, StrdupFailures) { EXPECT_EQ(ARES_SUCCESS, ares_library_init(ARES_LIB_INIT_ALL)); char* copy = ares_strdup("string"); EXPECT_NE(nullptr, copy); - free(copy); + ares_free(copy); ares_library_cleanup(); } @@ -248,7 +248,7 @@ TEST_F(LibraryTest, ReadLine) { TempFile temp("abcde\n0123456789\nXYZ\n012345678901234567890\n\n"); FILE *fp = fopen(temp.filename(), "r"); size_t bufsize = 4; - char *buf = (char *)malloc(bufsize); + char *buf = (char *)ares_malloc(bufsize); EXPECT_EQ(ARES_SUCCESS, ares__read_line(fp, &buf, &bufsize)); EXPECT_EQ("abcde", std::string(buf)); @@ -261,7 +261,7 @@ TEST_F(LibraryTest, ReadLine) { EXPECT_EQ(nullptr, buf); fclose(fp); - free(buf); + ares_free(buf); } TEST_F(LibraryTest, ReadLineNoBuf) { @@ -283,7 +283,7 @@ TEST_F(LibraryTest, ReadLineNoBuf) { EXPECT_EQ("012345678901234567890", std::string(buf)); fclose(fp); - free(buf); + ares_free(buf); } TEST(Misc, GetHostent) { @@ -373,7 +373,7 @@ TEST_F(DefaultChannelTest, SingleDomain) { channel_->flags |= ARES_FLAG_NOSEARCH|ARES_FLAG_NOALIASES; EXPECT_EQ(ARES_SUCCESS, single_domain(channel_, "www", &ptr)); EXPECT_EQ("www", std::string(ptr)); - free(ptr); + ares_free(ptr); ptr = nullptr; SetAllocFail(1); diff --git a/test/ares-test-misc.cc b/test/ares-test-misc.cc index 16142fe7..3db6405d 100644 --- a/test/ares-test-misc.cc +++ b/test/ares-test-misc.cc @@ -276,7 +276,7 @@ std::string ExpandName(const std::vector& data, int offset, } else { result = ""; } - free(name); + ares_free_string(name); return result; } @@ -467,7 +467,7 @@ TEST_F(LibraryTest, ExpandString) { (unsigned char**)&result, &len)); EXPECT_EQ("abc", std::string(result)); EXPECT_EQ(1 + 3, len); // amount of data consumed includes 1 byte len - free(result); + ares_free_string(result); result = nullptr; EXPECT_EQ(ARES_EBADSTR, ares_expand_string(s1.data() + 1, s1.data(), s1.size(), diff --git a/test/ares-test.cc b/test/ares-test.cc index ae14eecf..f5c59b72 100644 --- a/test/ares-test.cc +++ b/test/ares-test.cc @@ -280,7 +280,7 @@ void MockServer::ProcessFD(int fd) { qlen -= enclen; question += enclen; std::string namestr(name); - free(name); + ares_free_string(name); if (qlen < 4) { std::cerr << "Unexpected question size (" << qlen diff --git a/test/dns-proto.cc b/test/dns-proto.cc index 3f8918d4..d2fa8b15 100644 --- a/test/dns-proto.cc +++ b/test/dns-proto.cc @@ -248,7 +248,7 @@ std::string QuestionToString(const std::vector& packet, *len -= enclen; *data += enclen; ss << "'" << name << "' "; - free(name); + ares_free_string(name); if (*len < NS_QFIXEDSZ) { ss << "(too short, len left " << *len << ")"; return ss.str(); @@ -284,7 +284,7 @@ std::string RRToString(const std::vector& packet, *len -= enclen; *data += enclen; ss << "'" << name << "' "; - free(name); + ares_free_string(name); name = nullptr; if (*len < NS_RRFIXEDSZ) { @@ -336,7 +336,7 @@ std::string RRToString(const std::vector& packet, break; } ss << " '" << name << "'"; - free(name); + ares_free_string(name); break; } case ns_t_mx: @@ -347,7 +347,7 @@ std::string RRToString(const std::vector& packet, break; } ss << " " << DNS__16BIT(*data) << " '" << name << "'"; - free(name); + ares_free_string(name); } else { ss << "(RR too short)"; } @@ -365,7 +365,7 @@ std::string RRToString(const std::vector& packet, break; } ss << prio << " " << weight << " " << port << " '" << name << "'"; - free(name); + ares_free_string(name); } else { ss << "(RR too short)"; } @@ -379,7 +379,7 @@ std::string RRToString(const std::vector& packet, break; } ss << " '" << name << "'"; - free(name); + ares_free_string(name); p += enclen; rc = ares_expand_name(p, packet.data(), packet.size(), &name, &enclen); if (rc != ARES_SUCCESS) { @@ -387,7 +387,7 @@ std::string RRToString(const std::vector& packet, break; } ss << " '" << name << "'"; - free(name); + ares_free_string(name); p += enclen; if ((p + 20) <= (*data + rdatalen)) { unsigned long serial = DNS__32BIT(p); @@ -430,7 +430,7 @@ std::string RRToString(const std::vector& packet, break; } ss << " '" << name << "'"; - free(name); + ares_free_string(name); } else { ss << "(RR too short)"; }