Add NULL check logic for message callback 90/86190/1
authorHyunho Kang <hhstark.kang@samsung.com>
Wed, 31 Aug 2016 04:40:46 +0000 (13:40 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 31 Aug 2016 04:45:26 +0000 (13:45 +0900)
Change-Id: I6a0241ec2364e8b9eac0d8a0b56fe7067d733da8
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/message_port.c

index b6d22e7..971e829 100644 (file)
@@ -42,16 +42,23 @@ static void do_callback(message_port_message_cb callback, int local_port_id, con
 
 static void message_dispatcher(int local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data)
 {
-       message_port_callback_item *item =
-               (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
-       do_callback(item->callback, local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
+       message_port_callback_item *item = NULL;
+       if (__listeners == NULL)
+               return;
+       item = (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
+       if (item != NULL)
+               do_callback(item->callback, local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
 }
 
 static void trusted_message_dispatcher(int trusted_local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data)
 {
-       message_port_callback_item *item =
-               (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
-       do_callback(item->callback, trusted_local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
+       message_port_callback_item *item = NULL;
+
+       if (__trusted_listeners == NULL)
+               return;
+       item = (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
+       if (item != NULL)
+               do_callback(item->callback, trusted_local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
 }
 
 int message_port_register_local_port(const char *local_port, message_port_message_cb callback, void *user_data)