aboutsummaryrefslogtreecommitdiffstats
path: root/epan/plugin_if.c
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2018-01-16 16:38:50 +0100
committerMichael Mann <mmann78@netscape.net>2018-01-19 12:32:08 +0000
commit1b5624a71814baa38d9019d2c2d2a7e9d3437aeb (patch)
treedc685f4c49f80c21dc5cc6d6f948f0997bc45ca4 /epan/plugin_if.c
parenta8d40532c328282a04d2dc940e902f51bcf5adfd (diff)
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 <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/plugin_if.c')
-rw-r--r--epan/plugin_if.c24
1 files changed, 6 insertions, 18 deletions
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);
}
/*