diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-06-27 15:33:42 -0700 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-07-03 23:54:42 +0200 |
commit | ef0006ddf357b29c1c0d5dab3948172aabd0209f (patch) | |
tree | 4ffb29efb05681082b4e6310ca7f17554ed136d3 /asn1/snmp/packet-snmp-template.c | |
parent | e4490426d7ea252561d96e43f7ed2e164879e562 (diff) | |
download | wireshark-ef0006ddf357b29c1c0d5dab3948172aabd0209f.tar.gz |
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
Diffstat (limited to 'asn1/snmp/packet-snmp-template.c')
-rw-r--r-- | asn1/snmp/packet-snmp-template.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/asn1/snmp/packet-snmp-template.c b/asn1/snmp/packet-snmp-template.c index e5e6352465..5914dc99d3 100644 --- a/asn1/snmp/packet-snmp-template.c +++ b/asn1/snmp/packet-snmp-template.c @@ -1437,28 +1437,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 ) @@ -2569,7 +2579,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); } |