Skip to content

Commit a0ad9ec

Browse files
rsteinkeXMongoDB Bot
authored andcommitted
SERVER-89315 Minimize raw pointer usage in tryGetConnection() (#21555) (#33258)
GitOrigin-RevId: b1b7e3b8917cddbbd6b5dd2bd3ee5ffed269acae
1 parent e1d05c4 commit a0ad9ec

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/mongo/executor/connection_pool.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,17 +902,14 @@ ConnectionPool::ConnectionHandle ConnectionPool::SpecificPool::tryGetConnection(
902902
continue;
903903
}
904904

905-
auto connPtr = conn.get();
906-
907-
if (lease) {
908-
_leasedPool[connPtr] = std::move(conn);
909-
} else {
910-
_checkedOutPool[connPtr] = std::move(conn);
911-
}
905+
// Use a reference to the target map location as our connection,
906+
// so we're not juggling raw pointers any more than we need to.
907+
OwnedConnection& mappedConn = (lease ? _leasedPool : _checkedOutPool)[conn.get()];
908+
mappedConn = std::move(conn);
912909

913910
// pass it to the user
914-
connPtr->resetToUnknown();
915-
auto handle = makeHandle(connPtr, lease);
911+
mappedConn->resetToUnknown();
912+
auto handle = makeHandle(mappedConn.get(), lease);
916913
return handle;
917914
}
918915

0 commit comments

Comments
 (0)