From b54c43801112711dcba341f3eb4701678a0e1916 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Thu, 9 Feb 2017 12:28:14 -0500 Subject: Convert conversation hash tables to use wmem. Simplifies cleanup because wmem can handle the memory cleanup. Change-Id: Idc6a9bfe5f23c83b59a5278a64b9fb706862342d Reviewed-on: https://code.wireshark.org/review/20042 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/conversation.c | 114 ++++++++++++++++------------------------------------ 1 file changed, 35 insertions(+), 79 deletions(-) (limited to 'epan/conversation.c') diff --git a/epan/conversation.c b/epan/conversation.c index 1760270fa5..5d32c11721 100644 --- a/epan/conversation.c +++ b/epan/conversation.c @@ -39,39 +39,23 @@ int _debug_conversation_indent = 0; /* * Hash table for conversations with no wildcards. */ -static GHashTable *conversation_hashtable_exact = NULL; +static wmem_map_t *conversation_hashtable_exact = NULL; /* * Hash table for conversations with one wildcard address. */ -static GHashTable *conversation_hashtable_no_addr2 = NULL; +static wmem_map_t *conversation_hashtable_no_addr2 = NULL; /* * Hash table for conversations with one wildcard port. */ -static GHashTable *conversation_hashtable_no_port2 = NULL; +static wmem_map_t *conversation_hashtable_no_port2 = NULL; /* * Hash table for conversations with one wildcard address and port. */ -static GHashTable *conversation_hashtable_no_addr2_or_port2 = NULL; - - -#ifdef __NOT_USED__ -typedef struct conversation_key { - struct conversation_key *next; - address addr1; - address addr2; - port_type ptype; - guint32 port1; - guint32 port2; -} conversation_key; -#endif -/* - * Linked list of conversation keys, so we can, before freeing them all, - * free the address data allocations associated with them. - */ -static conversation_key *conversation_keys; +static wmem_map_t *conversation_hashtable_no_addr2_or_port2 = NULL; + static guint32 new_index; @@ -446,40 +430,8 @@ conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w) return 0; } -/* - * Destroy all existing conversations - */ -void -conversation_cleanup(void) -{ - /* Clean up the hash tables, but only after freeing any proto_data - * that may be hanging off the conversations. - * The conversation keys are wmem-allocated with file scope so we - * don't have to clean them up. - */ - conversation_keys = NULL; - if (conversation_hashtable_exact != NULL) { - g_hash_table_destroy(conversation_hashtable_exact); - } - if (conversation_hashtable_no_addr2 != NULL) { - g_hash_table_destroy(conversation_hashtable_no_addr2); - } - if (conversation_hashtable_no_port2 != NULL) { - g_hash_table_destroy(conversation_hashtable_no_port2); - } - if (conversation_hashtable_no_addr2_or_port2 != NULL) { - g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2); - } - - conversation_hashtable_exact = NULL; - conversation_hashtable_no_addr2 = NULL; - conversation_hashtable_no_port2 = NULL; - conversation_hashtable_no_addr2_or_port2 = NULL; -} - -/* - * Initialize some variables every time a file is loaded or re-loaded. - * Create a new hash table for the conversations in the new file. +/** + * Create a new hash tables for conversations. */ void conversation_init(void) @@ -493,18 +445,25 @@ conversation_init(void) * above. */ conversation_hashtable_exact = - g_hash_table_new(conversation_hash_exact, + wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), conversation_hash_exact, conversation_match_exact); conversation_hashtable_no_addr2 = - g_hash_table_new(conversation_hash_no_addr2, + wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), conversation_hash_no_addr2, conversation_match_no_addr2); conversation_hashtable_no_port2 = - g_hash_table_new(conversation_hash_no_port2, + wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), conversation_hash_no_port2, conversation_match_no_port2); conversation_hashtable_no_addr2_or_port2 = - g_hash_table_new(conversation_hash_no_addr2_or_port2, + wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), conversation_hash_no_addr2_or_port2, conversation_match_no_addr2_or_port2); +} + +/** + * Initialize some variables every time a file is loaded or re-loaded. + */ +void conversation_epan_reset(void) +{ /* * Start the conversation indices over at 0. */ @@ -518,17 +477,17 @@ conversation_init(void) * Mostly adapted from the old conversation_new(). */ static void -conversation_insert_into_hashtable(GHashTable *hashtable, conversation_t *conv) +conversation_insert_into_hashtable(wmem_map_t *hashtable, conversation_t *conv) { conversation_t *chain_head, *chain_tail, *cur, *prev; - chain_head = (conversation_t *)g_hash_table_lookup(hashtable, conv->key_ptr); + chain_head = (conversation_t *)wmem_map_lookup(hashtable, conv->key_ptr); if (NULL==chain_head) { /* New entry */ conv->next = NULL; conv->last = conv; - g_hash_table_insert(hashtable, conv->key_ptr, conv); + wmem_map_insert(hashtable, conv->key_ptr, conv); DPRINT(("created a new conversation chain")); } else { @@ -557,7 +516,7 @@ conversation_insert_into_hashtable(GHashTable *hashtable, conversation_t *conv) conv->next = chain_head; conv->last = chain_tail; chain_head->last = NULL; - g_hash_table_insert(hashtable, conv->key_ptr, conv); + wmem_map_insert(hashtable, conv->key_ptr, conv); } else { /* Inserting into the middle of the chain */ @@ -574,21 +533,20 @@ conversation_insert_into_hashtable(GHashTable *hashtable, conversation_t *conv) * taking into account ordering and hash chains and all that good stuff. */ static void -conversation_remove_from_hashtable(GHashTable *hashtable, conversation_t *conv) +conversation_remove_from_hashtable(wmem_map_t *hashtable, conversation_t *conv) { conversation_t *chain_head, *cur, *prev; - chain_head = (conversation_t *)g_hash_table_lookup(hashtable, conv->key_ptr); + chain_head = (conversation_t *)wmem_map_lookup(hashtable, conv->key_ptr); if (conv == chain_head) { /* We are currently the front of the chain */ if (NULL == conv->next) { /* We are the only conversation in the chain, no need to * update next pointer, but do not call - * g_hash_table_remove() either because the conv data - * will be re-inserted. The memory is released when - * conversion_cleanup() is called. */ - g_hash_table_steal(hashtable, conv->key_ptr); + * wmem_map_remove() either because the conv data + * will be re-inserted. */ + wmem_map_steal(hashtable, conv->key_ptr); } else { /* Update the head of the chain */ @@ -600,7 +558,7 @@ conversation_remove_from_hashtable(GHashTable *hashtable, conversation_t *conv) else chain_head->latest_found = conv->latest_found; - g_hash_table_insert(hashtable, chain_head->key_ptr, chain_head); + wmem_map_insert(hashtable, chain_head->key_ptr, chain_head); } } else { @@ -646,7 +604,7 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address DISSECTOR_ASSERT(!(options | CONVERSATION_TEMPLATE) || ((options | (NO_ADDR2 | NO_PORT2 | NO_PORT2_FORCE))) && "A conversation template may not be constructed without wildcard options"); */ - GHashTable* hashtable; + wmem_map_t* hashtable; conversation_t *conversation=NULL; conversation_key *new_key; @@ -669,8 +627,6 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address } new_key = wmem_new(wmem_file_scope(), struct conversation_key); - new_key->next = conversation_keys; - conversation_keys = new_key; copy_address_wmem(wmem_file_scope(), &new_key->addr1, addr1); copy_address_wmem(wmem_file_scope(), &new_key->addr2, addr2); new_key->ptype = ptype; @@ -775,7 +731,7 @@ conversation_set_addr2(conversation_t *conv, const address *addr) * {addr1, port1, addr2, port2} and set up before frame_num. */ static conversation_t * -conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, const address *addr1, const address *addr2, +conversation_lookup_hashtable(wmem_map_t *hashtable, const guint32 frame_num, const address *addr1, const address *addr2, const port_type ptype, const guint32 port1, const guint32 port2) { conversation_t* convo=NULL; @@ -793,7 +749,7 @@ conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, co key.port1 = port1; key.port2 = port2; - chain_head = (conversation_t *)g_hash_table_lookup(hashtable, &key); + chain_head = (conversation_t *)wmem_map_lookup(hashtable, &key); if (chain_head && (chain_head->setup_frame <= frame_num)) { match = chain_head; @@ -1316,25 +1272,25 @@ find_or_create_conversation(packet_info *pinfo) return conv; } -GHashTable * +wmem_map_t * get_conversation_hashtable_exact(void) { return conversation_hashtable_exact; } -GHashTable * +wmem_map_t * get_conversation_hashtable_no_addr2(void) { return conversation_hashtable_no_addr2; } -GHashTable * +wmem_map_t * get_conversation_hashtable_no_port2(void) { return conversation_hashtable_no_port2; } -GHashTable * +wmem_map_t * get_conversation_hashtable_no_addr2_or_port2(void) { return conversation_hashtable_no_addr2_or_port2; -- cgit v1.2.1