diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-06-27 15:33:42 -0700 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-07-04 00:17:14 +0000 |
commit | 3243b6f964c96f0137fc3fffd66a74dd9f7910fd (patch) | |
tree | cb4c47ada88b45cd7f6b1835cd412d1d60b746c2 /epan/dissectors/packet-snmp.c | |
parent | 7b33634cc562ba0ee75536b7dde4268a20d89bee (diff) |
asn1: split off cleanup routines
General approach:
1. Split allocation (e.g. g_hash_table_new) from deallocation
(g_hash_table_destroy) into functions named "init" and "cleanup".
2. Remove guards that test whether the hash tables are set as
init is always called before cleanup.
3. Remove setting hash tables to NULL after destruction.
4. Copy register_init_routine function call and change init to cleanup.
5. Add cleanup function that calls reassembly_table_destroy if there
is a reassembly_table_init function.
Some templates were modified as follows:
- snmp: split renew into init+cleanup, but keep renew for the uat_new
callback.
- ldap,ros: Rename init to cleanup as there was no initialization.
- camel: remove init function from header, make it static. Remove debug
print.
- tcap: remove unused ssn_range assignment.
Files in epan/ were regenerated using cmake && make asn1
Change-Id: Idac16ebf0ec304e0c8becaab5d32904e56eb69b9
Reviewed-on: https://code.wireshark.org/review/9136
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-snmp.c')
-rw-r--r-- | epan/dissectors/packet-snmp.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c index 2065b72d03..f909d62cdf 100644 --- a/epan/dissectors/packet-snmp.c +++ b/epan/dissectors/packet-snmp.c @@ -1539,28 +1539,38 @@ free_ue_cache(snmp_ue_assoc_t **cache) #define CACHE_INSERT(c,a) if (c) { snmp_ue_assoc_t* t = c; c = a; c->next = t; } else { c = a; a->next = NULL; } static void -renew_ue_cache(void) +init_ue_cache(void) { - free_ue_cache(&localized_ues); - free_ue_cache(&unlocalized_ues); - - if (num_ueas) { - guint i; + guint i; - for(i = 0; i < num_ueas; i++) { - snmp_ue_assoc_t* a = ue_dup(&(ueas[i])); + for (i = 0; i < num_ueas; i++) { + snmp_ue_assoc_t* a = ue_dup(&(ueas[i])); - if (a->engine.len) { - CACHE_INSERT(localized_ues,a); - - } else { - CACHE_INSERT(unlocalized_ues,a); - } + if (a->engine.len) { + CACHE_INSERT(localized_ues,a); + } else { + CACHE_INSERT(unlocalized_ues,a); } + } } +static void +cleanup_ue_cache(void) +{ + free_ue_cache(&localized_ues); + free_ue_cache(&unlocalized_ues); +} + +/* Called when the user applies changes to UAT preferences. */ +static void +renew_ue_cache(void) +{ + cleanup_ue_cache(); + init_ue_cache(); +} + static snmp_ue_assoc_t* localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len ) @@ -3077,7 +3087,7 @@ static int dissect_SMUX_PDUs_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, prot /*--- End of included file: packet-snmp-fn.c ---*/ -#line 1865 "../../asn1/snmp/packet-snmp-template.c" +#line 1875 "../../asn1/snmp/packet-snmp-template.c" guint @@ -3899,7 +3909,7 @@ void proto_register_snmp(void) { NULL, HFILL }}, /*--- End of included file: packet-snmp-hfarr.c ---*/ -#line 2422 "../../asn1/snmp/packet-snmp-template.c" +#line 2432 "../../asn1/snmp/packet-snmp-template.c" }; /* List of subtrees */ @@ -3939,7 +3949,7 @@ void proto_register_snmp(void) { &ett_snmp_RReqPDU_U, /*--- End of included file: packet-snmp-ettarr.c ---*/ -#line 2438 "../../asn1/snmp/packet-snmp-template.c" +#line 2448 "../../asn1/snmp/packet-snmp-template.c" }; static ei_register_info ei[] = { { &ei_snmp_failed_decrypted_data_pdu, { "snmp.failed_decrypted_data_pdu", PI_MALFORMED, PI_WARN, "Failed to decrypt encryptedPDU", EXPFILL }}, @@ -4074,7 +4084,8 @@ void proto_register_snmp(void) { value_sub_dissectors_table = register_dissector_table("snmp.variable_oid","SNMP Variable OID", FT_STRING, BASE_NONE); - register_init_routine(renew_ue_cache); + register_init_routine(init_ue_cache); + register_cleanup_routine(cleanup_ue_cache); register_ber_syntax_dissector("SNMP", proto_snmp, dissect_snmp_tcp); } |