From b33769a51244c1662bac1a3268a3862b7bff8db9 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Wed, 31 Aug 2016 13:40:46 +0900 Subject: [PATCH] Add NULL check logic for message callback Change-Id: I6a0241ec2364e8b9eac0d8a0b56fe7067d733da8 Signed-off-by: Hyunho Kang --- src/message_port.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/message_port.c b/src/message_port.c index b6d22e7..971e829 100644 --- a/src/message_port.c +++ b/src/message_port.c @@ -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) -- 2.7.4