Skip to content

Commit

Permalink
Fix memory leak in NaiveEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
larroy committed Jun 28, 2019
1 parent ca565a0 commit 6ed2af2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/engine/naive_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>
#include <atomic>
#include <thread>
#include <functional>
#include "./engine_impl.h"
#include "../profiler/profiler.h"
#include "./openmp.h"
Expand Down Expand Up @@ -159,15 +160,19 @@ 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);
//std::unique_ptr<NaiveOpr> opr;
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

0 comments on commit 6ed2af2

Please sign in to comment.