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

Commit

Permalink
Fix memory leak in NaiveEngine (#15405)
Browse files Browse the repository at this point in the history
* Fix memory leak in NaiveEngine
Fixes #15375

* Fix lint
  • Loading branch information
larroy authored and wkcn committed Jul 4, 2019
1 parent fc54781 commit faccc59
Showing 1 changed file with 6 additions and 3 deletions.
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

1 comment on commit faccc59

@KellenSunderland
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Please sign in to comment.