[nnfw_api] Prevent memory leakage in `nnfw_session::prepare` method (#5602)
authorСергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 <s.barannikov@samsung.com>
Wed, 10 Jul 2019 10:05:18 +0000 (13:05 +0300)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Wed, 10 Jul 2019 10:05:18 +0000 (19:05 +0900)
Use `make_unique` to ensure memory is freed in case of exception.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
runtimes/neurun/frontend/api/wrapper/nnfw_api.cc

index be4266a..0d4b966 100644 (file)
@@ -70,10 +70,9 @@ NNFW_STATUS nnfw_session::prepare()
 
   try
   {
-    auto compiler = new neurun::compiler::Compiler(_graph);
+    auto compiler = nnfw::cpp14::make_unique<neurun::compiler::Compiler>(_graph);
     compiler->compile();
     compiler->release(_executor);
-    delete compiler;
   }
   catch (...)
   {