From 1b5624a71814baa38d9019d2c2d2a7e9d3437aeb Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Tue, 16 Jan 2018 16:38:50 +0100 Subject: plugin_if: don't allocate memory and cast it instead. Glib hash table can use integers as pointer by casting them using GINT_TO_POINTER. This prevents alloc/free of memory. Leak found by clang. Change-Id: Ieae4d1ec787e41aef0657d27bdaefe30d12e2b80 Reviewed-on: https://code.wireshark.org/review/25341 Petri-Dish: Dario Lombardo Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/plugin_if.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'epan') diff --git a/epan/plugin_if.c b/epan/plugin_if.c index 635a6c992f..cb779327a0 100644 --- a/epan/plugin_if.c +++ b/epan/plugin_if.c @@ -44,26 +44,19 @@ static void plugin_if_init_hashtable(void) { if ( plugin_if_callback_functions == 0 ) - plugin_if_callback_functions = g_hash_table_new(g_int_hash, g_int_equal); + plugin_if_callback_functions = g_hash_table_new(g_direct_hash, g_direct_equal); } static void plugin_if_call_gui_cb(plugin_if_callback_t actionType, GHashTable * dataSet) { plugin_if_gui_cb action; - gint * key = 0; - - key = (gint *)g_malloc0(sizeof(gint)); - *key = (gint) actionType; plugin_if_init_hashtable(); - if ( g_hash_table_size(plugin_if_callback_functions) != 0 ) + if ( g_hash_table_lookup_extended(plugin_if_callback_functions, GINT_TO_POINTER(actionType), NULL, (gpointer*)&action) ) { - if ( g_hash_table_lookup_extended(plugin_if_callback_functions, key, NULL, (gpointer*)&action) ) - { - if ( action != NULL ) - action(dataSet); - } + if ( action != NULL ) + action(dataSet); } } @@ -596,15 +589,10 @@ extern void plugin_if_get_ws_info(ws_info_t **ws_info_ptr) extern void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback) { - gint * key = 0; - - key = (gint *)g_malloc0(sizeof(gint)); - *key = actionType; - plugin_if_init_hashtable(); - if ( ! g_hash_table_lookup_extended(plugin_if_callback_functions, key, NULL, NULL ) ) - g_hash_table_insert(plugin_if_callback_functions, key, (gpointer)callback); + if ( ! g_hash_table_lookup_extended(plugin_if_callback_functions, GINT_TO_POINTER(actionType), NULL, NULL ) ) + g_hash_table_insert(plugin_if_callback_functions, GINT_TO_POINTER(actionType), (gpointer)callback); } /* -- cgit v1.2.3