From df24be289221a37b55f9853d2083cf5a0a5382dc Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期四, 26 九月 2024 00:11:19 +0800
Subject: [PATCH] Revert "fix onnxruntime memoryleak when load model (#2108)"

---
 runtime/onnxruntime/src/fsmn-vad.h   |    4 +---
 runtime/onnxruntime/src/fsmn-vad.cpp |   11 ++++-------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/runtime/onnxruntime/src/fsmn-vad.cpp b/runtime/onnxruntime/src/fsmn-vad.cpp
index e347670..42ce83b 100644
--- a/runtime/onnxruntime/src/fsmn-vad.cpp
+++ b/runtime/onnxruntime/src/fsmn-vad.cpp
@@ -60,19 +60,18 @@
         LOG(ERROR) << "Error when load vad onnx model: " << e.what();
         exit(-1);
     }
-    GetInputOutputInfo(vad_session_, &vad_in_names_, &vad_out_names_, &vad_allocator);
+    GetInputOutputInfo(vad_session_, &vad_in_names_, &vad_out_names_);
 }
 
 void FsmnVad::GetInputOutputInfo(
         const std::shared_ptr<Ort::Session> &session,
-        std::vector<const char *> *in_names, std::vector<const char *> *out_names,
-        Ort::AllocatorWithDefaultOptions *allocator) {
+        std::vector<const char *> *in_names, std::vector<const char *> *out_names) {
     Ort::AllocatorWithDefaultOptions allocator;
     // Input info
     int num_nodes = session->GetInputCount();
     in_names->resize(num_nodes);
     for (int i = 0; i < num_nodes; ++i) {
-        std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetInputNameAllocated(i, *allocator);
+        std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetInputNameAllocated(i, allocator);
         Ort::TypeInfo type_info = session->GetInputTypeInfo(i);
         auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
         ONNXTensorElementDataType type = tensor_info.GetElementType();
@@ -91,7 +90,7 @@
     num_nodes = session->GetOutputCount();
     out_names->resize(num_nodes);
     for (int i = 0; i < num_nodes; ++i) {
-        std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetOutputNameAllocated(i, *allocator);
+        std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetOutputNameAllocated(i, allocator);
         Ort::TypeInfo type_info = session->GetOutputTypeInfo(i);
         auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
         ONNXTensorElementDataType type = tensor_info.GetElementType();
@@ -311,8 +310,6 @@
 }
 
 FsmnVad::~FsmnVad() {
-    for (auto vad_in_name_item : vad_in_names_) vad_allocator.Free((void*)vad_in_name_item);
-    for (auto vad_out_name_item : vad_out_names_) vad_allocator.Free((void*)vad_out_name_item);
 }
 
 FsmnVad::FsmnVad():env_(ORT_LOGGING_LEVEL_ERROR, ""),session_options_{} {
diff --git a/runtime/onnxruntime/src/fsmn-vad.h b/runtime/onnxruntime/src/fsmn-vad.h
index 5443a3b..f06a965 100644
--- a/runtime/onnxruntime/src/fsmn-vad.h
+++ b/runtime/onnxruntime/src/fsmn-vad.h
@@ -34,7 +34,6 @@
     std::shared_ptr<Ort::Session> vad_session_ = nullptr;
     Ort::Env env_;
     Ort::SessionOptions session_options_;
-    Ort::AllocatorWithDefaultOptions vad_allocator;
     std::vector<const char *> vad_in_names_;
     std::vector<const char *> vad_out_names_;
     std::vector<std::vector<float>> in_cache_;
@@ -57,8 +56,7 @@
 
     static void GetInputOutputInfo(
             const std::shared_ptr<Ort::Session> &session,
-            std::vector<const char *> *in_names, std::vector<const char *> *out_names,
-            Ort::AllocatorWithDefaultOptions *allocator);
+            std::vector<const char *> *in_names, std::vector<const char *> *out_names);
 
     void FbankKaldi(float sample_rate, std::vector<std::vector<float>> &vad_feats,
                     std::vector<float> &waves);

--
Gitblit v1.9.1