From ba9aa3015f29f07bf81cdfebdfab54fdc379b94d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 28 Jun 2015 15:15:07 +0200 Subject: Split more init routines into init/cleanup functions This patch is partially automatically generated, but are modified manually. In particular, assignments and function calls have been audited. Some debugging comments and ifdef'd prints have been removed. The lookup tables of the dcm and sip dissectors are now cleared. It is only called on reopening files anyway. The isakmp dissector is modified to use g_hash_table_new_full for destruction of its keys and values. Fix a memleak in ipsec dissector when libgcrypt is not enabled. Generated using https://git.lekensteyn.nl/peter/wireshark-notes/diff/one-off/cleanup-rewrite.py?id=3c6128ee266024d164650955f93c7740484abd68 (with AUDIT = True). Change-Id: I3fd910bdee663842ac0196334fe0189b67e251b0 Reviewed-on: https://code.wireshark.org/review/9225 Reviewed-by: Michael Mann --- epan/dissectors/packet-ipsec.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'epan/dissectors/packet-ipsec.c') diff --git a/epan/dissectors/packet-ipsec.c b/epan/dissectors/packet-ipsec.c index b7cfac4bea..72a3a9628f 100644 --- a/epan/dissectors/packet-ipsec.c +++ b/epan/dissectors/packet-ipsec.c @@ -2306,6 +2306,12 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } static void ipsec_init_protocol(void) +{ + esp_sequence_analysis_hash = g_hash_table_new(word_hash_func, word_equal); + esp_sequence_analysis_report_hash = g_hash_table_new(word_hash_func, word_equal); +} + +static void ipsec_cleanup_protocol(void) { #ifdef HAVE_LIBGCRYPT /* Free any SA records added by other dissectors */ @@ -2315,25 +2321,13 @@ static void ipsec_init_protocol(void) } /* Free overall block of records */ - if (extra_esp_sa_records.num_records > 0) { - g_free(extra_esp_sa_records.records); - extra_esp_sa_records.records = NULL; - } + g_free(extra_esp_sa_records.records); + extra_esp_sa_records.records = NULL; extra_esp_sa_records.num_records = 0; - - /* Destroy any existing hashes. */ - if (esp_sequence_analysis_hash) { - g_hash_table_destroy(esp_sequence_analysis_hash); - } - if (esp_sequence_analysis_report_hash) { - g_hash_table_destroy(esp_sequence_analysis_report_hash); - } #endif - /* Now create them over */ - esp_sequence_analysis_hash = g_hash_table_new(word_hash_func, word_equal); - esp_sequence_analysis_report_hash = g_hash_table_new(word_hash_func, word_equal); - + g_hash_table_destroy(esp_sequence_analysis_hash); + g_hash_table_destroy(esp_sequence_analysis_report_hash); } void @@ -2543,6 +2537,7 @@ proto_register_ipsec(void) #endif register_init_routine(&ipsec_init_protocol); + register_cleanup_routine(&ipsec_cleanup_protocol); register_dissector("esp", dissect_esp, proto_esp); register_dissector("ah", dissect_ah, proto_ah); -- cgit v1.2.3