diff options
author | Greg Studer <greg@10gen.com> | 2013-02-27 12:25:47 -0500 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2013-02-27 13:53:11 -0500 |
commit | 85f084463750f3cddb0792f45b3af2b19d4749b6 (patch) | |
tree | b444b1ef139595192cd6ad8e3269b223286c788e /src | |
parent | 82c8b3262103a89f0d29c51989f5063718b2ae5c (diff) | |
download | mongo-85f084463750f3cddb0792f45b3af2b19d4749b6.tar.gz |
SERVER-8765 fix memory leaks in config upgrade codepath
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/s/cluster_client_internal.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/mongo/s/cluster_client_internal.cpp b/src/mongo/s/cluster_client_internal.cpp index a5670926d2b..f24aaab4411 100644 --- a/src/mongo/s/cluster_client_internal.cpp +++ b/src/mongo/s/cluster_client_internal.cpp @@ -221,7 +221,8 @@ namespace mongo { BSONObj collDoc = cursor->nextSafe(); - CollectionType* coll = new CollectionType(); + // Replace with unique_ptr (also owned ptr map goes away) + auto_ptr<CollectionType> coll(new CollectionType()); string errMsg; coll->parseBSON(collDoc, &errMsg); @@ -245,8 +246,10 @@ namespace mongo { if (optionalEpochs && epochNotSet) { coll->setEpoch(OID()); } - - collections->mutableMap().insert(make_pair(coll->getNS(), coll)); + + // Get NS before releasing + string ns = coll->getNS(); + collections->mutableMap().insert(make_pair(ns, coll.release())); } } catch (const DBException& e) { @@ -286,7 +289,8 @@ namespace mongo { BSONObj chunkDoc = cursor->nextSafe(); - ChunkType* chunk = new ChunkType(); + // TODO: replace with unique_ptr when available + auto_ptr<ChunkType> chunk(new ChunkType()); string errMsg; if (!chunk->parseBSON(chunkDoc, &errMsg) || !chunk->isValid(&errMsg)) { connPtr->done(); @@ -295,7 +299,7 @@ namespace mongo { << " read from the config server" << causedBy(errMsg)); } - chunks->mutableVector().push_back(chunk); + chunks->mutableVector().push_back(chunk.release()); } } catch (const DBException& e) { |