From 117276c4135b0a3fbc0641a5c9f4d1ad9b44d785 Mon Sep 17 00:00:00 2001 From: ylavic Date: Sat, 27 Apr 2019 03:55:23 +0200 Subject: [PATCH] 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. --- test/unittest/documenttest.cpp | 2 ++ test/unittest/valuetest.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 472165f..c3d1e48 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -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); diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index f34d4b0..0a6b325 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -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());