Skip to content

Commit 21a87d7

Browse files
benetyEvergreen Agent
authored andcommitted
SERVER-49800 fix use-after-move violations in query
1 parent 406e8c3 commit 21a87d7

File tree

10 files changed

+16
-15
lines changed

10 files changed

+16
-15
lines changed

src/mongo/db/commands/find_cmd.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class FindCmd final : public Command {
316316
auto parsedNss =
317317
NamespaceString{CommandHelpers::parseNsFromCommand(_dbName, _request.body)};
318318
const bool isExplain = false;
319+
const bool isOplogNss = (parsedNss == NamespaceString::kRsOplogNamespace);
319320
auto qr =
320321
parseCmdObjectToQueryRequest(opCtx, std::move(parsedNss), _request.body, isExplain);
321322

@@ -344,7 +345,7 @@ class FindCmd final : public Command {
344345

345346
// The presence of a term in the request indicates that this is an internal replication
346347
// oplog read request.
347-
if (term && parsedNss == NamespaceString::kRsOplogNamespace) {
348+
if (term && isOplogNss) {
348349
// We do not want to take tickets for internal (replication) oplog reads. Stalling
349350
// on ticket acquisition can cause complicated deadlocks. Primaries may depend on
350351
// data reaching secondaries in order to proceed; and secondaries may get stalled

src/mongo/db/commands/plan_cache_commands.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(OperationContext* opCtx
9191
qr->setSort(sortObj);
9292
qr->setProj(projObj);
9393
qr->setCollation(collationObj);
94-
const ExtensionsCallbackReal extensionsCallback(opCtx, &nss);
94+
// TODO(SERVER-49997): remove clang-tidy NOLINT comment.
95+
const ExtensionsCallbackReal extensionsCallback(opCtx,
96+
&nss); // NOLINT(bugprone-use-after-move)
9597
const boost::intrusive_ptr<ExpressionContext> expCtx;
9698
auto statusWithCQ =
9799
CanonicalQuery::canonicalize(opCtx,

src/mongo/db/commands/run_aggregate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ Status runAggregate(OperationContext* opCtx,
717717
}
718718

719719
auto pin = CursorManager::get(opCtx)->registerCursor(opCtx, std::move(cursorParams));
720-
invariant(!exec);
721720

722721
cursors.emplace_back(pin.getCursor());
723722
pins.emplace_back(std::move(pin));

src/mongo/db/cst/pipeline_parser_gen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,8 +3327,8 @@ int PipelineParserGen::parse() {
33273327
| yyreturn -- parsing is finished, return the result. |
33283328
`-----------------------------------------------------*/
33293329
yyreturn:
3330-
if (!yyla.empty())
3331-
yy_destroy_("Cleanup: discarding lookahead", yyla);
3330+
if (!yyla.empty()) // NOLINT(bugprone-use-after-move)
3331+
yy_destroy_("Cleanup: discarding lookahead", yyla); // NOLINT(bugprone-use-after-move)
33323332

33333333
/* Do not reclaim the symbols of the rule whose action triggered
33343334
this YYABORT or YYACCEPT. */

src/mongo/db/exec/sbe/stages/hash_agg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ void HashAggStage::open(bool reOpen) {
103103
_commonStats.opens++;
104104
_children[0]->open(reOpen);
105105

106-
value::MaterializedRow key;
107106
while (_children[0]->getNext() == PlanState::ADVANCED) {
107+
value::MaterializedRow key;
108108
key._fields.resize(_inKeyAccessors.size());
109109
// Copy keys in order to do the lookup.
110110
size_t idx = 0;

src/mongo/db/exec/sbe/stages/hash_join.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ void HashJoinStage::open(bool reOpen) {
119119
_commonStats.opens++;
120120
_children[0]->open(reOpen);
121121
// Insert the outer side into the hash table.
122-
value::MaterializedRow key;
123-
value::MaterializedRow project;
124122

125123
while (_children[0]->getNext() == PlanState::ADVANCED) {
124+
value::MaterializedRow key;
125+
value::MaterializedRow project;
126126
key._fields.reserve(_inOuterKeyAccessors.size());
127127
project._fields.reserve(_inOuterProjectAccessors.size());
128128

src/mongo/db/exec/sbe/stages/sort.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ void SortStage::open(bool reOpen) {
121121
_commonStats.opens++;
122122
_children[0]->open(reOpen);
123123

124-
value::MaterializedRow keys;
125-
value::MaterializedRow vals;
126-
127124
SortOptions opts;
128125
opts.tempDir = storageGlobalParams.dbpath + "/_tmp";
129126
std::string spillFileName = opts.tempDir + "/" + nextFileName();
@@ -150,6 +147,8 @@ void SortStage::open(bool reOpen) {
150147
};
151148

152149
while (_children[0]->getNext() == PlanState::ADVANCED) {
150+
value::MaterializedRow keys;
151+
value::MaterializedRow vals;
153152
keys._fields.reserve(_inKeyAccessors.size());
154153
vals._fields.reserve(_inValueAccessors.size());
155154

src/mongo/db/exec/sbe/stages/spool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ void SpoolEagerProducerStage::open(bool reOpen) {
7979
_buffer->clear();
8080
}
8181

82-
value::MaterializedRow vals;
83-
8482
while (_children[0]->getNext() == PlanState::ADVANCED) {
83+
value::MaterializedRow vals;
8584
vals._fields.reserve(_inAccessors.size());
8685

8786
for (auto accessor : _inAccessors) {

src/mongo/db/pipeline/tee_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void TeeBuffer::loadNextBatch() {
9494
// - TeeBuffer is the only place where a paused GetNextReturn will be returned.
9595
// - The $facet stage is the only stage that uses TeeBuffer.
9696
// - We currently disallow nested $facet stages.
97-
invariant(!input.isPaused());
97+
invariant(!input.isPaused()); // NOLINT(bugprone-use-after-move)
9898

9999
// Populate the pending returns.
100100
for (size_t consumerId = 0; consumerId < _consumers.size(); ++consumerId) {

src/mongo/db/query/get_executor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,8 @@ class SlotBasedPrepareExecutionHelper final
919919
const QueryPlannerParams& plannerParams,
920920
size_t decisionWorks) final {
921921
auto result = makeResult();
922-
result->emplace(buildExecutableTree(*solution, true), std::move(solution));
922+
auto execTree = buildExecutableTree(*solution, true);
923+
result->emplace(std::move(execTree), std::move(solution));
923924
result->setDecisionWorks(decisionWorks);
924925
return result;
925926
}

0 commit comments

Comments
 (0)