Seems like auto iterator = rs->getIterator(txn) should be wrapped in a std::unique_ptr.
================================================================= ==57562==ERROR: LeakSanitizer: detected memory leaks Direct leak of 40 byte(s) in 1 object(s) allocated from: #0 0x932539 in operator new(unsigned long) (/data/mci/src/mongod+0x932539) #1 0x1f50033 in mongo::SimpleRecordStoreV1::getIterator(mongo::OperationContext*, mongo::RecordId const&, mongo::CollectionScanParams::Direction const&) const /data/mci/src/src/mongo/db/storage/mmap_v1/record_store_v1_simple.cpp:242 #2 0x1edb015 in mongo::MMAPV1DatabaseCatalogEntry::_init(mongo::OperationContext*) /data/mci/src/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp:565 #3 0x1ed802e in mongo::MMAPV1DatabaseCatalogEntry::MMAPV1DatabaseCatalogEntry(mongo::OperationContext*, mongo::StringData const&, mongo::StringData const&, bool, bool) /data/mci/src/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp:183 #4 0x1efbfbd in mongo::MMAPV1Engine::getDatabaseCatalogEntry(mongo::OperationContext*, mongo::StringData const&) /data/mci/src/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp:269 #5 0xdc0df4 in mongo::DatabaseHolder::openDb(mongo::OperationContext*, mongo::StringData const&, bool*) /data/mci/src/src/mongo/db/catalog/database_holder.cpp:120 #6 0xe04d4b in mongo::AutoGetOrCreateDb::AutoGetOrCreateDb(mongo::OperationContext*, mongo::StringData const&, mongo::LockMode) /data/mci/src/src/mongo/db/client.cpp:214 #7 0x94e58a in mongo::logStartup() /data/mci/src/src/mongo/db/db.cpp:268 #8 0x94e58a in mongo::_initAndListen(int) /data/mci/src/src/mongo/db/db.cpp:654 #9 0x94819b in mongo::initAndListen(int) /data/mci/src/src/mongo/db/db.cpp:666 #10 0x9592c0 in mongoDbMain(int, char**, char**) /data/mci/src/src/mongo/db/db.cpp:905 #11 0x9592c0 in main /data/mci/src/src/mongo/db/db.cpp:711 #12 0x7f245893eec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) ----------------------------------------------------- Suppressions used: count bytes template 28 34816 mongo::Client::Client ----------------------------------------------------- SUMMARY: AddressSanitizer: 40 byte(s) leaked in 1 allocation(s).