summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Zolnierz <nicholas.zolnierz@mongodb.com>2020-09-11 14:36:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-14 17:34:41 +0000
commitb80b53bde9cfd36fbf2d50e129d123ba8f35df48 (patch)
tree199529bf284302ed3ee4d96b7222a12109f2e45c
parentec929e17993ade6e0258aab73fd8024d1cb6180f (diff)
downloadmongo-b80b53bde9cfd36fbf2d50e129d123ba8f35df48.tar.gz
SERVER-50895 Fix leak of $unionWith cached pipeline for explain when execution does not read from sub-pipeline
-rw-r--r--src/mongo/db/pipeline/document_source_union_with.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_union_with.h5
2 files changed, 3 insertions, 4 deletions
diff --git a/src/mongo/db/pipeline/document_source_union_with.cpp b/src/mongo/db/pipeline/document_source_union_with.cpp
index 294b16accc3..3191468d65b 100644
--- a/src/mongo/db/pipeline/document_source_union_with.cpp
+++ b/src/mongo/db/pipeline/document_source_union_with.cpp
@@ -267,7 +267,7 @@ Value DocumentSourceUnionWith::serialize(boost::optional<ExplainOptions::Verbosi
// We've either exhausted the sub-pipeline or at least started iterating it. Use the
// cached pipeline to get the explain output since the '_pipeline' may have been
// modified for any optimizations or pushdowns into the initial $cursor stage.
- pipeCopy = _cachedPipeline;
+ pipeCopy = Pipeline::create(_cachedPipeline, _pipeline->getContext()).release();
} else {
// The plan does not require reading from the sub-pipeline, so just include the
// serialization in the explain output.
diff --git a/src/mongo/db/pipeline/document_source_union_with.h b/src/mongo/db/pipeline/document_source_union_with.h
index 5686f569374..38f5eeeb804 100644
--- a/src/mongo/db/pipeline/document_source_union_with.h
+++ b/src/mongo/db/pipeline/document_source_union_with.h
@@ -66,8 +66,7 @@ public:
// If this pipeline is being run as part of explain, then cache a copy to use later during
// serialization.
if (expCtx->explain >= ExplainOptions::Verbosity::kExecStats) {
- _cachedPipeline =
- Pipeline::create(_pipeline->getSources(), _pipeline->getContext()).release();
+ _cachedPipeline = _pipeline->getSources();
}
}
@@ -162,7 +161,7 @@ private:
void addViewDefinition(NamespaceString nss, std::vector<BSONObj> viewPipeline);
std::unique_ptr<Pipeline, PipelineDeleter> _pipeline;
- Pipeline* _cachedPipeline = nullptr;
+ Pipeline::SourceContainer _cachedPipeline;
bool _usedDisk = false;
ExecutionProgress _executionState = ExecutionProgress::kIteratingSource;
};