Fix would-crash tests if the default allocator used were kNeedFree.

The allocator cannot be destroyed before the Document, otherwise the
Value destructor double frees.
This commit is contained in:
ylavic 2019-04-27 03:55:23 +02:00
parent 50cb424c34
commit 117276c413
2 changed files with 4 additions and 2 deletions

View File

@ -325,6 +325,8 @@ TEST(Document, Swap) {
EXPECT_TRUE(d1.IsNull());
// reset document, including allocator
// so clear o before so that it doesnt contain dangling elements
o.Clear();
Document().Swap(d2);
EXPECT_TRUE(d2.IsNull());
EXPECT_NE(&d2.GetAllocator(), &a);

View File

@ -1078,9 +1078,9 @@ static void TestArray(T& x, Allocator& allocator) {
}
TEST(Value, Array) {
Value::AllocatorType allocator;
Value x(kArrayType);
const Value& y = x;
Value::AllocatorType allocator;
EXPECT_EQ(kArrayType, x.GetType());
EXPECT_TRUE(x.IsArray());
@ -1491,9 +1491,9 @@ static void TestObject(T& x, Allocator& allocator) {
}
TEST(Value, Object) {
Value::AllocatorType allocator;
Value x(kObjectType);
const Value& y = x; // const version
Value::AllocatorType allocator;
EXPECT_EQ(kObjectType, x.GetType());
EXPECT_TRUE(x.IsObject());