Add null check when calling event callback 15/312515/1
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 11 Jun 2024 04:39:29 +0000 (13:39 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 11 Jun 2024 04:44:47 +0000 (13:44 +0900)
Change-Id: Iaa4e7bb26f07989fef80dd1532a4d1fcdb49887a

client/src/signal_receiver.cc

index b4761f0..bf020bb 100644 (file)
@@ -94,7 +94,7 @@ void SignalReceiver::HandleHandler(int targetUid,
     if (cb) {
       cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(),
           key.c_str(), val.c_str(), nullptr, data);
-    } else {
+    } else if (app_cb) {
       app_cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(),
           i.GetAppid().c_str(), key.c_str(), val.c_str(), nullptr, data);
     }
@@ -109,7 +109,7 @@ void SignalReceiver::HandleGlobalHandler(int targetUid,
       if (cb) {
         cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(),
             key.c_str(), val.c_str(), nullptr, data);
-      } else {
+      } else if (app_cb) {
         app_cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(),
             i.GetAppid().c_str(), key.c_str(), val.c_str(), nullptr, data);
       }
@@ -124,6 +124,8 @@ void SignalReceiver::HandleSizeInfoHandler(
   if (it == size_info_handlers_.end())
     return;
   const auto& [id, cb, pc, data] = it->second;
+  if (!cb)
+    return;
 
   std::vector<std::string> tokens;
   std::istringstream ss(val);
@@ -179,7 +181,8 @@ void SignalReceiver::OnAsyncResultForResource(std::string signal,
 void SignalReceiver::OnAsyncResultForPkgUpgrade(
     std::string signal, int progress) {
   for (const auto& [id, cb, data] : global_pkg_upgrade_handlers_) {
-    cb(progress, data);
+    if (cb)
+      cb(progress, data);
   }
 }
 
@@ -191,16 +194,18 @@ void SignalReceiver::HandleResHandler(const std::string& signal,
     return;
   const auto& [id, cb, data] = it->second;
 
-  cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(),
-      static_cast<void*>(&extra), data);
+  if (cb)
+    cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(),
+        static_cast<void*>(&extra), data);
 }
 
 void SignalReceiver::HandleGlobalResHandler(const std::string& signal,
     int targetUid, const std::string& reqId, const std::string& pkgid,
     const std::string& status, pkg_signal::ExtraData& extra) const {
   for (const auto& [id, cb, data] : global_res_handlers_) {
-    cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(),
-        static_cast<void*>(&extra), data);
+    if (cb)
+      cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(),
+          static_cast<void*>(&extra), data);
   }
 }