Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix memory leak in NaiveEngine #15405

Merged
merged 2 commits into from
Jul 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/engine/naive_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ class NaiveEngine final : public Engine {
NaiveEngine::OnComplete, nullptr);
this->req_completed_ = false;
profiler::Profiler *profiler = profiler::Profiler::Get();
NaiveOpr *opr = nullptr;
auto opr_deleter = [this](NaiveOpr* p) {
this->DeleteOperator(p);
};
std::unique_ptr<NaiveOpr, decltype(opr_deleter)> opr(nullptr, opr_deleter);
const bool profiling = opr_name && profiler->IsProfiling(profiler::Profiler::kImperative);
// GenerateDisplayName() will return a pointer to the correct name of the operator
const char* display_name = profiling ?
profiler::CustomOpProfiler::Get()->GenerateDisplayName(opr_name) :
opr_name;
if (profiling) {
opr = NewOperator(exec_fun, const_vars, mutable_vars,
prop, display_name)->Cast<NaiveOpr>();
opr.reset(NewOperator(exec_fun, const_vars, mutable_vars,
prop, display_name)->Cast<NaiveOpr>());
opr->profiling = profiling;
std::unique_ptr<profiler::ProfileOperator::Attributes> attrs;
if (profiler->AggregateEnabled()) {
Expand Down