summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/documenttests.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-08-19 11:51:46 -0400
committerMathias Stearn <mathias@10gen.com>2013-08-19 15:47:44 -0400
commit6fea4eb1774119e6431bf251d008d062c67c73f2 (patch)
treef2f6682fa21b4337ba1c17a0e075e21c362d0608 /src/mongo/dbtests/documenttests.cpp
parent176e5716c009535bfa2ee074d0b2f74c7ab4beda (diff)
downloadmongo-6fea4eb1774119e6431bf251d008d062c67c73f2.tar.gz
SERVER-10554 Patch memory leak in aggregation
The issue was that empty documents are represented as a NULL pointer and Value didn't ref count NULL pointers. This is fine for all public interactions with Value, however MutableDocument can change the pointer in-place when updating a nested field. This caused a leak when it transitioned a Value from holding a non-refcounted NULL pointer to holding a real pointer since MutableDocument/MutableValue didn't set the refCount bit.
Diffstat (limited to 'src/mongo/dbtests/documenttests.cpp')
-rw-r--r--src/mongo/dbtests/documenttests.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/dbtests/documenttests.cpp b/src/mongo/dbtests/documenttests.cpp
index c220c17abca..7017240a876 100644
--- a/src/mongo/dbtests/documenttests.cpp
+++ b/src/mongo/dbtests/documenttests.cpp
@@ -167,6 +167,22 @@ namespace DocumentTests {
ASSERT( md.peek()["c"].missing() );
assertRoundTrips( md.peek() );
+ // Set a nested field using []
+ md["x"]["y"]["z"] = Value("nested");
+ ASSERT_EQUALS(md.peek()["x"]["y"]["z"], Value("nested"));
+
+ // Set a nested field using setNestedField
+ FieldPath xxyyzz = string("xx.yy.zz");
+ md.setNestedField(xxyyzz, Value("nested"));
+ ASSERT_EQUALS(md.peek().getNestedField(xxyyzz), Value("nested") );
+
+ // Set a nested fields through an existing empty document
+ md["xxx"] = Value(Document());
+ md["xxx"]["yyy"] = Value(Document());
+ FieldPath xxxyyyzzz = string("xxx.yyy.zzz");
+ md.setNestedField(xxxyyyzzz, Value("nested"));
+ ASSERT_EQUALS(md.peek().getNestedField(xxxyyyzzz), Value("nested") );
+
// Make sure nothing moved
ASSERT_EQUALS(apos, md.peek().positionOf("a"));
ASSERT_EQUALS(bpos, md.peek().positionOf("c"));