Skip to content

Commit 117276c

Browse files
committed
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.
1 parent 50cb424 commit 117276c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

test/unittest/documenttest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ TEST(Document, Swap) {
325325
EXPECT_TRUE(d1.IsNull());
326326

327327
// reset document, including allocator
328+
// so clear o before so that it doesnt contain dangling elements
329+
o.Clear();
328330
Document().Swap(d2);
329331
EXPECT_TRUE(d2.IsNull());
330332
EXPECT_NE(&d2.GetAllocator(), &a);

test/unittest/valuetest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,9 @@ static void TestArray(T& x, Allocator& allocator) {
10781078
}
10791079

10801080
TEST(Value, Array) {
1081+
Value::AllocatorType allocator;
10811082
Value x(kArrayType);
10821083
const Value& y = x;
1083-
Value::AllocatorType allocator;
10841084

10851085
EXPECT_EQ(kArrayType, x.GetType());
10861086
EXPECT_TRUE(x.IsArray());
@@ -1491,9 +1491,9 @@ static void TestObject(T& x, Allocator& allocator) {
14911491
}
14921492

14931493
TEST(Value, Object) {
1494+
Value::AllocatorType allocator;
14941495
Value x(kObjectType);
14951496
const Value& y = x; // const version
1496-
Value::AllocatorType allocator;
14971497

14981498
EXPECT_EQ(kObjectType, x.GetType());
14991499
EXPECT_TRUE(x.IsObject());

0 commit comments

Comments
 (0)