Fix wrong user_data management 86/144686/2
authorjusung son <jusung07.son@samsung.com>
Thu, 17 Aug 2017 11:34:14 +0000 (20:34 +0900)
committerjusung son <jusung07.son@samsung.com>
Thu, 17 Aug 2017 11:42:52 +0000 (20:42 +0900)
Change-Id: I4e604cb89f34960d17f4647ce1b9c3a8a1ad17a8
Signed-off-by: jusung son <jusung07.son@samsung.com>
src/message_port_remote.c

index a1b71289531509ae3c5ffabdb7fd530c44649e29..6f22f40c49974a4a3d167ea03ed39825b55a00f9 100755 (executable)
@@ -60,8 +60,7 @@ typedef struct message_port_pkt {
 } message_port_pkt_s;
 
 typedef struct message_port_callback_info {
-       message_port_message_cb callback;
-       void *user_data;
+       message_port_local_port_info_s *local_info;
        int local_id;
        char *remote_app_id;
        GIOChannel *gio_read;
@@ -274,6 +273,7 @@ static gboolean __socket_request_handler(GIOChannel *gio,
        int fd = 0;
        message_port_callback_info_s *mi;
        message_port_pkt_s *pkt;
+       message_port_local_port_info_s *local_port_info;
        bundle *kb = NULL;
        GError *error = NULL;
 
@@ -289,43 +289,47 @@ static gboolean __socket_request_handler(GIOChannel *gio,
                return FALSE;
        }
 
-       if (cond == G_IO_HUP) {
+       local_port_info = mi->local_info;
+       if (local_port_info == NULL || local_port_info->callback == NULL) {
+               _LOGE("Failed to get callback info");
+               __callback_info_free_by_info(mi);
+               return FALSE;
+       }
 
+       if (cond == G_IO_HUP) {
                _LOGI("socket G_IO_HUP");
                __callback_info_free_by_info(mi);
                return FALSE;
+       }
 
-       } else {
+       if ((fd = g_io_channel_unix_get_fd(gio)) < 0) {
+               _LOGE("fail to get fd from io channel");
+               __callback_info_free_by_info(mi);
+               return FALSE;
+       }
 
-               if ((fd = g_io_channel_unix_get_fd(gio)) < 0) {
-                       _LOGE("fail to get fd from io channel");
-                       __callback_info_free_by_info(mi);
-                       return FALSE;
-               }
+       if ((pkt = __message_port_recv_raw(fd)) == NULL) {
+               _LOGE("recv error on SOCKET");
+               __callback_info_free_by_info(mi);
+               return FALSE;
+       }
 
-               if ((pkt = __message_port_recv_raw(fd)) == NULL) {
-                       _LOGE("recv error on SOCKET");
-                       __callback_info_free_by_info(mi);
-                       return FALSE;
-               }
+       kb = bundle_decode(pkt->data, pkt->data_len);
+       if (pkt->is_bidirection)
+               local_port_info->callback(mi->local_id, mi->remote_app_id,
+                       pkt->remote_port_name, pkt->is_trusted, kb, local_port_info->user_data);
 
-               kb = bundle_decode(pkt->data, pkt->data_len);
-               if (pkt->is_bidirection) {
-                       if (mi->callback)
-                               mi->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, pkt->is_trusted, kb, mi->user_data);
-               } else {
-                       if (mi->callback)
-                               mi->callback(mi->local_id, mi->remote_app_id, NULL, pkt->is_trusted, kb, mi->user_data);
-               }
+       else
+               local_port_info->callback(mi->local_id, mi->remote_app_id,
+                       NULL, pkt->is_trusted, kb, local_port_info->user_data);
 
-               bundle_free(kb);
-               if (pkt) {
-                       if (pkt->remote_port_name)
-                               free(pkt->remote_port_name);
-                       if (pkt->data)
-                               free(pkt->data);
-                       free(pkt);
-               }
+       bundle_free(kb);
+       if (pkt) {
+               if (pkt->remote_port_name)
+                       free(pkt->remote_port_name);
+               if (pkt->data)
+                       free(pkt->data);
+               free(pkt);
        }
 
        return TRUE;
@@ -415,13 +419,12 @@ static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invoc
        }
 
        callback_info->local_id = mi->local_id;
+       callback_info->local_info = mi;
        callback_info->remote_app_id = strdup(local_appid);
        if (callback_info->remote_app_id == NULL) {
                _LOGE("out of memory");
                goto out;
        }
-       callback_info->callback = mi->callback;
-       callback_info->user_data = mi->user_data;
 
        msg = g_dbus_method_invocation_get_message(invocation);
        fd_list = g_dbus_message_get_unix_fd_list(msg);
@@ -460,7 +463,7 @@ static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invoc
                                }
                                head_callback_info->local_id = 0;
                                head_callback_info->remote_app_id = NULL;
-                               head_callback_info->callback = NULL;
+                               head_callback_info->local_info = NULL;
                                head_callback_info->gio_read = NULL;
                                head_callback_info->g_src_id = 0;
                                callback_info_list = g_list_append(callback_info_list, head_callback_info);
@@ -480,9 +483,9 @@ static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invoc
 
        LOGD("call calback %s", local_appid);
        if (bi_dir)
-               mi->callback(mi->local_id, local_appid, local_port, local_trusted, data, NULL);
+               mi->callback(mi->local_id, local_appid, local_port, local_trusted, data, mi->user_data);
        else
-               mi->callback(mi->local_id, local_appid, NULL, false, data, NULL);
+               mi->callback(mi->local_id, local_appid, NULL, false, data, mi->user_data);
        bundle_free(data);
 
        ret = true;