Split four more init routines into init/cleanup

Three of them are trivial movements, the smb-sidsnooping is an odd one.
Ronnie Sahlberg disabled the sid_name_snooping feature on 9 July 2007.
There is a preference to override it though... For now add a TODO
marker and ensure that the hash tables are always initialized.

Change-Id: I61f5e215c9fa72a6785fb48eaa2d50c1975d7483
Reviewed-on: https://code.wireshark.org/review/9227
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Peter Wu 2015-06-28 07:35:00 -07:00 committed by Michael Mann
parent f5340b2a07
commit 7ce77c69ea
4 changed files with 45 additions and 103 deletions

View File

@ -1593,58 +1593,21 @@ static void read_IOR_strings_from_file(const gchar *name, int max_iorlen) {
*/
static void giop_init(void) {
/*
* Create objkey/repoid hash, use my "equal" and "hash" functions.
* Note: keys and values are wmem_file_scoped so they don't need to be freed.
*
*/
if (giop_objkey_hash)
g_hash_table_destroy(giop_objkey_hash);
/*
* Create hash, use my "equal" and "hash" functions.
*
*/
giop_objkey_hash = g_hash_table_new(giop_hash_objkey_hash, giop_hash_objkey_equal);
/*
* Create complete_reply_hash, use my "equal" and "hash" functions.
* Note: keys and values are wmem_file_scoped so they don't need to be freed.
*
*/
if (giop_complete_reply_hash)
g_hash_table_destroy(giop_complete_reply_hash);
/*
* Create hash, use my "equal" and "hash" functions.
*
*/
giop_complete_reply_hash = g_hash_table_new(complete_reply_hash_fn, complete_reply_equal_fn);
/*
* Free giop_complete_request_list (if necessary)
* Note: The data elements are wmem_file_scoped so only the
* actual list elements need to be freed.
*/
if (giop_complete_request_list) {
g_list_free(giop_complete_request_list);
giop_complete_request_list = NULL;
}
giop_complete_request_list = NULL;
read_IOR_strings_from_file(giop_ior_file, 600);
reassembly_table_init(&giop_reassembly_table,
&addresses_reassembly_table_functions);
}
static void giop_cleanup(void) {
reassembly_table_destroy(&giop_reassembly_table);
g_hash_table_destroy(giop_objkey_hash);
g_hash_table_destroy(giop_complete_reply_hash);
g_list_free(giop_complete_request_list);
}
@ -5560,6 +5523,7 @@ proto_register_giop (void)
/* register init routine */
register_init_routine( &giop_init); /* any init stuff */
register_cleanup_routine( &giop_cleanup);
/* Register for tapping */
giop_tap = register_tap(GIOP_TAP_NAME); /* GIOP statistics tap */

View File

@ -1322,20 +1322,18 @@ static void p_mul_init_routine (void)
reassembly_table_init (&p_mul_reassembly_table,
&addresses_reassembly_table_functions);
message_id_offset = 0;
if (p_mul_id_hash_table) {
g_hash_table_destroy (p_mul_id_hash_table);
}
if (p_mul_package_data_list) {
g_list_foreach (p_mul_package_data_list, (GFunc)p_mul_package_data_destroy, NULL);
g_list_free (p_mul_package_data_list);
}
p_mul_id_hash_table = g_hash_table_new_full (p_mul_id_hash, p_mul_id_hash_equal, NULL, (GDestroyNotify)p_mul_id_value_destroy);
p_mul_package_data_list = NULL;
}
static void p_mul_cleanup_routine (void)
{
reassembly_table_destroy(&p_mul_reassembly_table);
g_hash_table_destroy(p_mul_id_hash_table);
g_list_foreach(p_mul_package_data_list, (GFunc)p_mul_package_data_destroy, NULL);
g_list_free(p_mul_package_data_list);
}
void proto_register_p_mul (void)
{
static hf_register_info hf[] = {
@ -1583,6 +1581,7 @@ void proto_register_p_mul (void)
expert_p_mul = expert_register_protocol(proto_p_mul);
expert_register_field_array(expert_p_mul, ei, array_length(ei));
register_init_routine (&p_mul_init_routine);
register_cleanup_routine (&p_mul_cleanup_routine);
/* Set default UDP ports */
range_convert_str (&global_p_mul_port_range, DEFAULT_P_MUL_PORT_RANGE,

View File

@ -557,24 +557,6 @@ static void
fragment_table_init(void)
{
int i;
if (fragment_table) {
g_hash_table_destroy(fragment_table);
}
if (endpoints) {
g_hash_table_destroy(endpoints);
}
if (reassembled_table) {
g_hash_table_destroy(reassembled_table);
}
if (sequence_table) {
g_hash_table_destroy(sequence_table);
}
if (duplicate_table) {
g_hash_table_destroy(duplicate_table);
}
if(counter_map){
g_tree_destroy(counter_map);
}
fragment_table = g_hash_table_new_full(rlc_channel_hash, rlc_channel_equal, rlc_channel_delete, NULL);
endpoints = g_hash_table_new_full(rlc_channel_hash, rlc_channel_equal, rlc_channel_delete, NULL);
reassembled_table = g_hash_table_new_full(rlc_frag_hash, rlc_frag_equal,
@ -594,6 +576,17 @@ fragment_table_init(void)
max_counter = 0;
}
static void
fragment_table_cleanup(void)
{
g_tree_destroy(counter_map);
g_hash_table_destroy(fragment_table);
g_hash_table_destroy(endpoints);
g_hash_table_destroy(reassembled_table);
g_hash_table_destroy(sequence_table);
g_hash_table_destroy(duplicate_table);
}
/* add the list of fragments for this sdu to 'tree' */
static void
tree_add_fragment_list(struct rlc_sdu *sdu, tvbuff_t *tvb, proto_tree *tree)
@ -3000,6 +2993,7 @@ proto_register_rlc(void)
#endif /* HAVE_UMTS_KASUMI */
register_init_routine(fragment_table_init);
register_cleanup_routine(fragment_table_cleanup);
}
void

View File

@ -259,20 +259,13 @@ lsa_policy_information(void *dummy _U_, packet_info *pinfo _U_, epan_dissect_t *
return 0;
}
static gboolean
free_all_sid_names(gpointer key_arg, gpointer value _U_, gpointer user_data _U_)
static void
sid_name_key_destroy(gpointer key_arg)
{
sid_name *sn = (sid_name *)key_arg;
if(sn->sid){
g_free((gpointer)sn->sid);
sn->sid=NULL;
}
if(sn->name){
g_free((gpointer)sn->name);
sn->name=NULL;
}
return TRUE;
g_free((gpointer)sn->sid);
g_free((gpointer)sn->name);
}
static gint
@ -298,11 +291,6 @@ sid_name_hash(gconstpointer k)
}
static gboolean
free_all_ctx_handle(gpointer key_arg _U_, gpointer value _U_, gpointer user_data _U_)
{
return TRUE;
}
static gint
ctx_handle_equal(gconstpointer k1, gconstpointer k2)
{
@ -335,17 +323,10 @@ sid_snooping_init(void)
samr_query_dispinfo_tap_installed=FALSE;
}
if(sid_name_table){
g_hash_table_foreach_remove(sid_name_table, free_all_sid_names, NULL);
sid_name_table=NULL;
}
if(ctx_handle_table){
g_hash_table_foreach_remove(ctx_handle_table, free_all_ctx_handle, NULL);
ctx_handle_table=NULL;
}
/* this code needs to be rewritten from scratch
sid_name_table = g_hash_table_new_full(sid_name_hash, sid_name_equal,
sid_name_key_destroy, NULL);
ctx_handle_table = g_hash_table_new(ctx_handle_hash, ctx_handle_equal);
/* TODO this code needs to be rewritten from scratch
disabling it now so that it won't cause wireshark to abort due to
unknown hf fields
*/
@ -355,10 +336,6 @@ sid_name_snooping=FALSE;
return;
}
sid_name_table=g_hash_table_new(sid_name_hash, sid_name_equal);
ctx_handle_table=g_hash_table_new(ctx_handle_hash, ctx_handle_equal);
#if 0
@ -403,10 +380,18 @@ sid_name_snooping=FALSE;
samr_query_dispinfo_tap_installed=TRUE;
}
static void
sid_snooping_cleanup(void)
{
g_hash_table_destroy(sid_name_table);
g_hash_table_destroy(ctx_handle_table);
}
void
proto_register_smb_sidsnooping(void)
{
register_init_routine(sid_snooping_init);
register_cleanup_routine(sid_snooping_cleanup);
}
/*