diff options
author | Aaron <aaron@10gen.com> | 2009-01-06 14:27:05 -0500 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-01-06 14:27:05 -0500 |
commit | d91a66e744b1761ad26cbc5d7e33ba43e4277765 (patch) | |
tree | 372c938da37871ddf25702dcb82acd342eda3d21 /db | |
parent | dcb974a59ff55333b38f7ae93b84855db2289250 (diff) | |
download | mongo-d91a66e744b1761ad26cbc5d7e33ba43e4277765.tar.gz |
Free bson builders if unable to parse
Diffstat (limited to 'db')
-rw-r--r-- | db/json.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/db/json.cpp b/db/json.cpp index e1c907ca50d..7a5f0b03d6c 100644 --- a/db/json.cpp +++ b/db/json.cpp @@ -23,19 +23,18 @@ using namespace boost::spirit; struct ObjectBuilder { - BSONObjBuilder *back() { return builders.back(); } + BSONObjBuilder *back() { return builders.back().get(); } // Storage for field names of elements within builders.back(). const char *fieldName() { return fieldNames.back().c_str(); } void push() { - builders.push_back( new BSONObjBuilder() ); + boost::shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() ); + builders.push_back( b ); fieldNames.push_back( "" ); indexes.push_back( 0 ); } BSONObj pop() { - BSONObjBuilder *b = builders.back(); + BSONObj ret = back()->doneAndDecouple(); builders.pop_back(); - BSONObj ret = b->doneAndDecouple(); - free( b ); fieldNames.pop_back(); indexes.pop_back(); return ret; @@ -48,7 +47,8 @@ struct ObjectBuilder { ss.str( "" ); return ret; } - vector< BSONObjBuilder* > builders; + // Cannot use auto_ptr because its copy constructor takes a non const reference. + vector< boost::shared_ptr< BSONObjBuilder > > builders; vector< string > fieldNames; vector< int > indexes; stringstream ss; |