From: Sangjung Woo Date: Thu, 26 Jan 2023 07:46:02 +0000 (+0900) Subject: [ML][Single] Fix the crash issue in SingleShot class X-Git-Tag: accepted/tizen/unified/20230202.015309^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5acf81c3ac03c00e66a6398e1ae10a4c27f08c9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [ML][Single] Fix the crash issue in SingleShot class ml_single_close() can be called in both Close() method and destructor of SingleShot class. If the handle is invalid, calling ml_single_close() can cause the segmentation fault issue. This patch checks whether the handle is valid or not so it fixes the potential bug. Change-Id: I0ab94cae99f53d274a091acb3a21403f42664439 Signed-off-by: Sangjung Woo --- diff --git a/src/ml/ml_singleshot.cc b/src/ml/ml_singleshot.cc index 226c7fb7..65211ff5 100644 --- a/src/ml/ml_singleshot.cc +++ b/src/ml/ml_singleshot.cc @@ -51,9 +51,12 @@ 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)); + int ret = 0; + if (handle_ != nullptr) { + 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_) { @@ -263,6 +266,7 @@ PlatformResult SingleShot::Close() { return util::ToPlatformResult(ret, "Failed to close"); } + handle_ = nullptr; return PlatformResult{}; }