From: Chanwoo Choi Date: Wed, 6 Jul 2022 09:16:29 +0000 (+0900) Subject: monitor: request-handler: Fix wrong hash function when using integer key X-Git-Tag: submit/tizen/20220714.022316~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af1f87f100cfafb316285c5a8349530fe379ed62;p=platform%2Fcore%2Fsystem%2Fpass.git monitor: request-handler: Fix wrong hash function when using integer key The glib hash supports the various hash type. The resource-monitor uses the integer value of resource id as the key of hash. If want to use the integer key value, have to use 'g_direct_hash'[1] function and 'g_direct_equal' function to compare the integer key instead of pointer key for finding the inserted data. [1] https://docs.gtk.org/glib/func.direct_hash.html [2] https://docs.gtk.org/glib/func.direct_equal.html Fix the following issues by this patch: [ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_ctrl/0 [ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_set_resource_attr/0 [ FAILED ] ResourceMonitorTest/EachResourceMonitorTest.pass_resource_monitor_get_value/0 Change-Id: I128fd800d44e5709d55d0c7a44a80db94e6d83d8 Signed-off-by: Chanwoo Choi --- diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index 184631d..482132a 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -55,13 +55,13 @@ static void update_resource(gpointer key, gpointer value, gpointer user_data) static void register_resource_to_client(struct request_client *client, struct resource *res) { - g_hash_table_insert(client->resource_table, (gpointer)&res->id, (gpointer)res); -} + g_hash_table_insert(client->resource_table, GINT_TO_POINTER(res->id), + (gpointer)res); static void unregister_resource_from_client(struct request_client *client, int resource_id) { - g_hash_table_remove(client->resource_table, (gpointer)&resource_id); + g_hash_table_remove(client->resource_table, GINT_TO_POINTER(resource_id)); } static struct resource * @@ -69,7 +69,7 @@ get_resource_by_id(struct request_client *client, int resource_id) { struct resource *res; - res = g_hash_table_lookup(client->resource_table, (gpointer)&resource_id); + res = g_hash_table_lookup(client->resource_table, GINT_TO_POINTER(resource_id)); return res; } @@ -830,7 +830,7 @@ int create_request_client(int socket_fd) } client->socket_fd = socket_fd; - client->resource_table = g_hash_table_new_full(g_int_hash, g_int_equal, + client->resource_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)delete_resource); create_daemon_thread(&client->worker, request_handler_func, client);