[libcxx] Fix memory leak in strstream tests.
Summary: The strstream function `str()` sets `freeze(true)`. When `freeze` is true the destructor is not allowed to free any dynamically allocated memory. The memory leak causes ASAN to fail on these tests. To ensure memory is deallocated `strstream.freeze(false)` is called at the end of the tests. Reviewers: danalbert, mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6261 llvm-svn: 222025
This commit is contained in:
parent
1cbb971c2d
commit
93f65c4d08
|
@ -24,4 +24,5 @@ int main()
|
||||||
std::string s("dog");
|
std::string s("dog");
|
||||||
out << i << ' ' << d << ' ' << s << std::ends;
|
out << i << ' ' << d << ' ' << s << std::ends;
|
||||||
assert(out.str() == std::string("123 4.5 dog"));
|
assert(out.str() == std::string("123 4.5 dog"));
|
||||||
|
out.freeze(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,6 @@ int main()
|
||||||
out << 'a';
|
out << 'a';
|
||||||
out << char(0);
|
out << char(0);
|
||||||
assert(out.str() == std::string("a"));
|
assert(out.str() == std::string("a"));
|
||||||
|
out.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@ int main()
|
||||||
std::ostrstream out;
|
std::ostrstream out;
|
||||||
out << 123 << ' ' << 4.5 << ' ' << "dog" << std::ends;
|
out << 123 << ' ' << 4.5 << ' ' << "dog" << std::ends;
|
||||||
assert(out.str() == std::string("123 4.5 dog"));
|
assert(out.str() == std::string("123 4.5 dog"));
|
||||||
|
out.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,5 @@ int main()
|
||||||
assert(i == 123);
|
assert(i == 123);
|
||||||
assert(d == 4.5);
|
assert(d == 4.5);
|
||||||
assert(strcmp(s.c_str(), "dog") == 0);
|
assert(strcmp(s.c_str(), "dog") == 0);
|
||||||
|
inout.freeze(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,6 @@ int main()
|
||||||
out << 'a';
|
out << 'a';
|
||||||
out << char(0);
|
out << char(0);
|
||||||
assert(out.str() == std::string("a"));
|
assert(out.str() == std::string("a"));
|
||||||
|
out.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@ int main()
|
||||||
std::strstream out;
|
std::strstream out;
|
||||||
out << 123 << ' ' << 4.5 << ' ' << "dog" << std::ends;
|
out << 123 << ' ' << 4.5 << ' ' << "dog" << std::ends;
|
||||||
assert(out.str() == std::string("123 4.5 dog"));
|
assert(out.str() == std::string("123 4.5 dog"));
|
||||||
|
out.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,5 +27,6 @@ int main()
|
||||||
assert(sb.pcount() == 2);
|
assert(sb.pcount() == 2);
|
||||||
assert(sb.str() == std::string("a"));
|
assert(sb.str() == std::string("a"));
|
||||||
assert(sb.pcount() == 2);
|
assert(sb.pcount() == 2);
|
||||||
|
sb.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,6 @@ int main()
|
||||||
assert(sb.sputc('a') == 'a');
|
assert(sb.sputc('a') == 'a');
|
||||||
assert(sb.sputc(0) == 0);
|
assert(sb.sputc(0) == 0);
|
||||||
assert(sb.str() == std::string("a"));
|
assert(sb.str() == std::string("a"));
|
||||||
|
sb.freeze(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue