Fix hash table usage for request callback 94/127194/2
authorjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 26 Apr 2017 10:51:27 +0000 (19:51 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Wed, 26 Apr 2017 13:47:46 +0000 (13:47 +0000)
The req_id was not used as key directly.
And destory function for key was not correct impl.

Use req_id as key directly
and desory function for value should be used.

Change-Id: I3df0de320a6641df797ff7c5268981a87059fd74
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/package_manager.c

index 73534ec..aa21455 100644 (file)
@@ -93,19 +93,21 @@ static int package_manager_new_id()
 
 static void __free_request_cb_info(gpointer data)
 {
+       int req_id;
        struct package_manager_request_cb_info *cb_info =
                        (struct package_manager_request_cb_info *)data;
 
+       req_id = cb_info->req_id;
        free(cb_info);
        cb_info = NULL;
 
-       _LOGD("request callback info removed");
+       _LOGD("request callback info removed, req_id(%d)", req_id);
 }
 
 static void __initialize_request_cb_table(void)
 {
        __request_cb_table =
-               g_hash_table_new_full(g_int_hash, g_int_equal, __free_request_cb_info, NULL);
+               g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __free_request_cb_info);
 }
 
 static int __insert_request_cb_info(int req_id, package_manager_request_event_cb callback, void *user_data)
@@ -118,7 +120,7 @@ static int __insert_request_cb_info(int req_id, package_manager_request_event_cb
        cb_info->req_id = req_id;
        cb_info->callback = callback;
        cb_info->user_data = user_data;
-       g_hash_table_insert(__request_cb_table, &cb_info->req_id, cb_info);
+       g_hash_table_insert(__request_cb_table, GINT_TO_POINTER(cb_info->req_id), cb_info);
 
        return 0;
 }
@@ -529,7 +531,7 @@ static int internal_request_callback(uid_t target_uid, int req_id, const char *p
        _LOGD("request callback called, req_id[%d]", req_id);
 
        package_manager_request_h request = data;
-       cb_info = g_hash_table_lookup(__request_cb_table, &req_id);
+       cb_info = g_hash_table_lookup(__request_cb_table, GINT_TO_POINTER(req_id));
        if (!cb_info || (cb_info && !cb_info->callback)) {
                _LOGE("no callback info");
                return 0;
@@ -604,7 +606,7 @@ static int internal_request_callback(uid_t target_uid, int req_id, const char *p
                } else {
                        _LOGE("unexpected end event");
                }
-               g_hash_table_remove(__request_cb_table, &req_id);
+               g_hash_table_remove(__request_cb_table, GINT_TO_POINTER(req_id));
        }
 
        return 0;