summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2013-02-27 12:25:47 -0500
committerGreg Studer <greg@10gen.com>2013-02-27 13:53:11 -0500
commit85f084463750f3cddb0792f45b3af2b19d4749b6 (patch)
treeb444b1ef139595192cd6ad8e3269b223286c788e /src
parent82c8b3262103a89f0d29c51989f5063718b2ae5c (diff)
downloadmongo-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.cpp14
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) {