Add to set res_fn_ to nullptr 17/257817/5
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 3 May 2021 08:26:20 +0000 (17:26 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 3 May 2021 09:16:23 +0000 (18:16 +0900)
Changes:
 - Set res_fn_ to nullptr after calling it.
 - Add some logs for debugging.

Change-Id: I85287fa4edd0f606ff60dff87fcbb1b2f7fec496
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/aul_svc.cc

index 98b5826..5441bc4 100644 (file)
@@ -219,9 +219,15 @@ void LaunchWithResultCb(bundle* b, int is_cancel, void* data) {
 
   bundle_del(b, AUL_SVC_K_RES_VAL);
   auto* cb_info = static_cast<CbInfo*>(data);
+  if (cb_info == nullptr) {
+    _E("Invalid parameter");
+    return;
+  }
+
   if (cb_info->res_fn_) {
     cb_info->res_fn_(b, cb_info->request_code_,
         static_cast<aul_svc_result_val>(res), cb_info->user_data_);
+    cb_info->res_fn_ = nullptr;
   }
 
   if (cb_info->err_cb_ != nullptr)
@@ -235,6 +241,11 @@ void ErrorCb(int error, void* data) {
     error = AulErrorConvert(error);
 
   auto* cb_info = static_cast<CbInfo*>(data);
+  if (cb_info == nullptr) {
+    _E("Invalid parameter");
+    return;
+  }
+
   if (cb_info->err_cb_) {
     cb_info->err_cb_(cb_info->request_code_, error, cb_info->user_data_);
     cb_info->err_cb_ = nullptr;
@@ -405,6 +416,8 @@ extern "C" API int aul_svc_run_service_for_uid(bundle* b, int request_code,
   CbInfo* cb_info = nullptr;
   if (cbfunc)
     cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, nullptr, data);
+  if (cb_info == nullptr)
+    LOGE("Out of memory");
 
   std::tuple<aul_svc_res_fn, void*> param { cbfunc, data };
   int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
@@ -753,6 +766,9 @@ extern "C" API int aul_svc_send_launch_request_for_uid(bundle* b,
 
   CbInfo* cb_info = new (std::nothrow) CbInfo(request_code, cbfunc, err_cb,
       user_data);
+  if (cb_info == nullptr)
+    _E("Out of memory");
+
   int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
       [](const std::string& appid, bundle* request, uid_t uid,
         CbInfo* info) -> int {
@@ -1019,6 +1035,9 @@ extern "C" API int aul_svc_send_resume_request_for_uid(bundle* b,
 
   auto* cb_info = new (std::nothrow) CbInfo(request_code, nullptr, err_cb,
       user_data);
+  if (cb_info == nullptr)
+    _E("Out of memory");
+
   int ret = ::SendLaunchRequest<::SendLaunchRequestCb, ::CbInfo*>(
       [](const std::string& appid, bundle* request, uid_t uid,
           CbInfo* info) -> int {