From e162efb0434b95eabfe5be7e019caea6fc1a6ab6 Mon Sep 17 00:00:00 2001 From: Sangjung Woo Date: Fri, 24 Sep 2021 16:38:09 +0900 Subject: [PATCH] [ML][Single] Fix the crash issue in single API 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 --- src/ml/ml_singleshot.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ml/ml_singleshot.cc b/src/ml/ml_singleshot.cc index da397f6a..226c7fb7 100644 --- a/src/ml/ml_singleshot.cc +++ b/src/ml/ml_singleshot.cc @@ -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) { -- 2.34.1