You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by wk...@apache.org on 2019/07/04 00:37:22 UTC

[incubator-mxnet] branch master updated: Fix memory leak in NaiveEngine (#15405)

This is an automated email from the ASF dual-hosted git repository.

wkcn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new faccc59  Fix memory leak in NaiveEngine (#15405)
faccc59 is described below

commit faccc59bc0ed7e22933c1f86f3aabac6f13fe1a9
Author: Pedro Larroy <pe...@gmail.com>
AuthorDate: Wed Jul 3 17:36:56 2019 -0700

    Fix memory leak in NaiveEngine (#15405)
    
    * Fix memory leak in NaiveEngine
    Fixes #15375
    
    * Fix lint
---
 src/engine/naive_engine.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/engine/naive_engine.cc b/src/engine/naive_engine.cc
index 9f44b55..9cfe9b2 100644
--- a/src/engine/naive_engine.cc
+++ b/src/engine/naive_engine.cc
@@ -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()) {