test: use ares_free_string() throughout

As pointed out by Gisle Vanem in #125.
pull/128/head
David Drysdale 7 years ago
parent 245edc4fa4
commit 82a4d111ba
  1. 10
      test/ares-test-internal.cc
  2. 4
      test/ares-test-misc.cc
  3. 2
      test/ares-test.cc
  4. 16
      test/dns-proto.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);

@ -276,7 +276,7 @@ std::string ExpandName(const std::vector<byte>& data, int offset,
} else {
result = "<error>";
}
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(),

@ -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

@ -248,7 +248,7 @@ std::string QuestionToString(const std::vector<byte>& 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<byte>& 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<byte>& 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<byte>& 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<byte>& 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<byte>& 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<byte>& 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<byte>& packet,
break;
}
ss << " '" << name << "'";
free(name);
ares_free_string(name);
} else {
ss << "(RR too short)";
}

Loading…
Cancel
Save