[ML][Single] Fix the crash issue in single API 43/264543/1
authorSangjung Woo <sangjung.woo@samsung.com>
Fri, 24 Sep 2021 07:38:09 +0000 (16:38 +0900)
committerSangjung Woo <sangjung.woo@samsung.com>
Fri, 24 Sep 2021 07:38:09 +0000 (16:38 +0900)
Before closing the singleshot handle, the output tensor data is freed.
Since inference internally is going on, this situation could cause the
segmentation fault in sub-plugin part. This patch fixes that bug.

Change-Id: I690b4ef941e981353f3809cc56a1f2089ef2a4e5
Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
src/ml/ml_singleshot.cc

index da397f6..226c7fb 100644 (file)
@@ -50,27 +50,27 @@ SingleShot::SingleShot(SingleShot&& o)
 
 SingleShot::~SingleShot() {
   ScopeLogger("id: %d", id_);
+
+  int ret = ml_single_close(handle_);
+  if (ML_ERROR_NONE != ret) {
+    LoggerW("ml_single_close failed: %d (%s)", ret, get_error_message(ret));
+  }
   // not dynamic mode uses ml_single_invoke_fast, which reuses handles, so they need to be freed
   if (!dynamic_mode_) {
     if (nullptr != tensor_data_out_handle_) {
-      int ret = ml_tensors_data_destroy(tensor_data_out_handle_);
+      ret = ml_tensors_data_destroy(tensor_data_out_handle_);
       if (ML_ERROR_NONE != ret) {
         LoggerW("ml_tensors_data_destroy failed: %d (%s)", ret, get_error_message(ret));
       }
     }
 
     if (nullptr != tensor_info_out_handle_) {
-      int ret = ml_tensors_info_destroy(tensor_info_out_handle_);
+      ret = ml_tensors_info_destroy(tensor_info_out_handle_);
       if (ML_ERROR_NONE != ret) {
         LoggerW("ml_tensors_info_destroy failed: %d (%s)", ret, get_error_message(ret));
       }
     }
   }
-
-  int ret = ml_single_close(handle_);
-  if (ML_ERROR_NONE != ret) {
-    LoggerW("ml_single_close failed: %d (%s)", ret, get_error_message(ret));
-  }
 }
 
 PlatformResult SingleShot::GetTensorsInfo(bool get_input_mode, ml_tensors_info_h* result) {