diff --git a/src/engine/naive_engine.cc b/src/engine/naive_engine.cc index 9f44b55cfcaf..f153a04338d5 100644 --- a/src/engine/naive_engine.cc +++ b/src/engine/naive_engine.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include "./engine_impl.h" #include "../profiler/profiler.h" #include "./openmp.h" @@ -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 opr(nullptr, opr_deleter); + //std::unique_ptr 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(); + opr.reset(NewOperator(exec_fun, const_vars, mutable_vars, + prop, display_name)->Cast()); opr->profiling = profiling; std::unique_ptr attrs; if (profiler->AggregateEnabled()) {