From: Ilho Kim Date: Tue, 11 Jun 2024 04:39:29 +0000 (+0900) Subject: Add null check when calling event callback X-Git-Tag: accepted/tizen/unified/20240612.095951~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb6f8af9f2cfa9a99ca87583d2232847d5af1f62;p=platform%2Fcore%2Fappfw%2Fslp-pkgmgr.git Add null check when calling event callback Change-Id: Iaa4e7bb26f07989fef80dd1532a4d1fcdb49887a --- diff --git a/client/src/signal_receiver.cc b/client/src/signal_receiver.cc index b4761f0..bf020bb 100644 --- a/client/src/signal_receiver.cc +++ b/client/src/signal_receiver.cc @@ -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 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(&extra), data); + if (cb) + cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(), + static_cast(&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(&extra), data); + if (cb) + cb(targetUid, id, pkgid.c_str(), signal.c_str(), status.c_str(), + static_cast(&extra), data); } }