summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/legacy_reply_builder.cpp
diff options
context:
space:
mode:
authorAdam Midvidy <amidvidy@gmail.com>2015-06-15 14:15:15 -0400
committerAdam Midvidy <amidvidy@gmail.com>2015-06-16 16:25:39 -0400
commitd124312c4c7d34678565a2607d13a016279b9893 (patch)
tree984bc36ef408e4b961a285e88a510a99f77e35b0 /src/mongo/rpc/legacy_reply_builder.cpp
parent49c54afb7abfeceb0f9f03ed59df69b9cf22a5e7 (diff)
downloadmongo-d124312c4c7d34678565a2607d13a016279b9893.tar.gz
SERVER-18236 fix exception safety in generateErrorResponse
Diffstat (limited to 'src/mongo/rpc/legacy_reply_builder.cpp')
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 69134af3628..e95c6ceff8b 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -86,6 +86,18 @@ namespace rpc {
return rpc::Protocol::kOpQuery;
}
+ void LegacyReplyBuilder::reset() {
+ // If we are in State::kMetadata, we are already in the 'start' state, so by
+ // immediately returning, we save a heap allocation.
+ if (_state == State::kMetadata) {
+ return;
+ }
+ _builder.reset();
+ _metadata = BSONObj();
+ _message = stdx::make_unique<Message>();
+ _state = State::kMetadata;
+ }
+
std::unique_ptr<Message> LegacyReplyBuilder::done() {
invariant(_state == State::kOutputDocs);
std::unique_ptr<Message> message = stdx::make_unique<Message>();