Check IEventWatcher ptr before calling the method 55/209655/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 9 Jul 2019 22:58:28 +0000 (07:58 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 9 Jul 2019 23:05:40 +0000 (08:05 +0900)
This patch add exceptions to check whether the watcher variable is
nullptr or not.

Change-Id: I846cc3181be4907fc4b6a8178625fe4da34ea45c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/fdbroker-internal.cc

index 7509e93..a059c92 100644 (file)
@@ -601,7 +601,10 @@ void FdBroker::OnResultReceived(GObject* source_object,
       res, &err);
   if (reply == nullptr) {
     LOGE("No reply. err(%s)", err ? err->message : "Unknown");
-    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
+    if (watcher) {
+      watcher->OnPortDisconnected(broker->watch_appid_,
+          broker->watch_port_name_);
+    }
     g_error_free(err);
     return;
   }
@@ -609,7 +612,10 @@ void FdBroker::OnResultReceived(GObject* source_object,
   GVariant* reply_body = g_dbus_message_get_body(reply);
   if (reply_body == nullptr) {
     LOGE("g_dbus_message_get_body() is failed");
-    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
+    if (watcher) {
+      watcher->OnPortDisconnected(broker->watch_appid_,
+          broker->watch_port_name_);
+    }
     g_object_unref(reply);
     return;
   }
@@ -619,11 +625,13 @@ void FdBroker::OnResultReceived(GObject* source_object,
   g_object_unref(reply);
   if (ret != 0) {
     LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str());
-    watcher->OnPortRejected(broker->watch_appid_);
+    if (watcher)
+      watcher->OnPortRejected(broker->watch_appid_);
     return;
   }
 
-  watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_);
+  if (watcher)
+    watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_);
   LOGD("[Reply : %d]", ret);
 }