0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Free bson builders if unable to parse

This commit is contained in:
Aaron 2009-01-06 14:27:05 -05:00
parent dcb974a59f
commit d91a66e744
2 changed files with 7 additions and 6 deletions

View File

@ -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;

View File

@ -273,6 +273,7 @@ inline void our_debug_free(void *p) {
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/shared_ptr.hpp>
#define BOOST_SPIRIT_THREADSAFE
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/core.hpp>