summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-06-28 16:10:51 -0700
committerPeter Wu <peter@lekensteyn.nl>2015-07-03 23:54:44 +0200
commit62b279fcaf9ccb0e348a456abd47d6e7338a765e (patch)
treeb27370c7a7a89455f3ce7af5aeab26f25665920b
parent669ce38be4867fbfa523dbe736f170739c7e6804 (diff)
downloadwireshark-62b279fcaf9ccb0e348a456abd47d6e7338a765e.tar.gz
Split init routine into init/cleanup for more dissectors
This patch converts some dissectors using g_hash_table_foreach_remove. - 9p: drop no-op free func. - nfs: use g_hash_table_new_full such that a destructor function can be used. Drop NULL check since g_free can handle these just fine. - nlm: use g_hash_table_new_full such that a destructor function can be used. Simplify "matched" destruction by replacing the wrapper by a direct g_free call. Change-Id: I455e7f0ad4e47e70dae05af7233fdcdebf583f9f
-rw-r--r--epan/dissectors/packet-9p.c17
-rw-r--r--epan/dissectors/packet-nfs.c61
-rw-r--r--epan/dissectors/packet-nlm.c42
3 files changed, 44 insertions, 76 deletions
diff --git a/epan/dissectors/packet-9p.c b/epan/dissectors/packet-9p.c
index 878100443d..9aa1ae87b5 100644
--- a/epan/dissectors/packet-9p.c
+++ b/epan/dissectors/packet-9p.c
@@ -1013,11 +1013,6 @@ static guint _9p_hash_hash(gconstpointer k)
return (key->conv_index ^ key->tag ^ key->fid);
}
-static gboolean _9p_hash_free_all(gpointer key _U_, gpointer value _U_, gpointer user_data _U_)
-{
- return TRUE;
-}
-
static void _9p_hash_free_val(gpointer value)
{
struct _9p_hashval *val = (struct _9p_hashval *)value;
@@ -1043,11 +1038,12 @@ static struct _9p_hashval *_9p_hash_new_val(gsize len)
static void _9p_hash_init(void)
{
- if (_9p_hashtable != NULL) {
- g_hash_table_foreach_remove(_9p_hashtable, _9p_hash_free_all, NULL);
- } else {
- _9p_hashtable = g_hash_table_new_full(_9p_hash_hash, _9p_hash_equal, g_free, _9p_hash_free_val);
- }
+ _9p_hashtable = g_hash_table_new_full(_9p_hash_hash, _9p_hash_equal, g_free, _9p_hash_free_val);
+}
+
+static void _9p_hash_cleanup(void)
+{
+ g_hash_table_destroy(_9p_hashtable);
}
static void _9p_hash_set(packet_info *pinfo, guint16 tag, guint32 fid, struct _9p_hashval *val)
@@ -2757,6 +2753,7 @@ void proto_register_9P(void)
expert_register_field_array(expert_9P, ei, array_length(ei));
register_init_routine(_9p_hash_init);
+ register_cleanup_routine(_9p_hash_cleanup);
}
void proto_reg_handoff_9P(void)
diff --git a/epan/dissectors/packet-nfs.c b/epan/dissectors/packet-nfs.c
index 6cf663d2ce..262fb63c4a 100644
--- a/epan/dissectors/packet-nfs.c
+++ b/epan/dissectors/packet-nfs.c
@@ -949,55 +949,37 @@ nfs_name_snoop_unmatched_hash(gconstpointer k)
}
-static gboolean
-nfs_name_snoop_unmatched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
+static void
+nfs_name_snoop_value_destroy(gpointer value)
{
nfs_name_snoop_t *nns = (nfs_name_snoop_t *)value;
- if (nns->name) {
- g_free((gpointer)nns->name);
- nns->name = NULL;
- nns->name_len = 0;
- }
- if (nns->full_name) {
- g_free((gpointer)nns->full_name);
- nns->full_name = NULL;
- nns->full_name_len = 0;
- }
- if (nns->parent) {
- g_free((gpointer)nns->parent);
- nns->parent = NULL;
- nns->parent_len = 0;
- }
- if (nns->fh) {
- g_free((gpointer)nns->fh);
- nns->fh = NULL;
- nns->fh_length = 0;
- }
+ g_free((gpointer)nns->name);
+ g_free((gpointer)nns->full_name);
+ g_free((gpointer)nns->parent);
+ g_free((gpointer)nns->fh);
g_free(nns);
- return TRUE;
}
static void
nfs_name_snoop_init(void)
{
- if (nfs_name_snoop_unmatched != NULL) {
- g_hash_table_foreach_remove(nfs_name_snoop_unmatched,
- nfs_name_snoop_unmatched_free_all, NULL);
- } else {
- /* The fragment table does not exist. Create it */
- nfs_name_snoop_unmatched = g_hash_table_new(nfs_name_snoop_unmatched_hash,
- nfs_name_snoop_unmatched_equal);
- }
- if (nfs_name_snoop_matched != NULL) {
- g_hash_table_foreach_remove(nfs_name_snoop_matched,
- nfs_name_snoop_unmatched_free_all, NULL);
- } else {
- /* The fragment table does not exist. Create it */
- nfs_name_snoop_matched = g_hash_table_new(nfs_name_snoop_matched_hash,
- nfs_name_snoop_matched_equal);
- }
+ nfs_name_snoop_unmatched =
+ g_hash_table_new_full(nfs_name_snoop_unmatched_hash,
+ nfs_name_snoop_unmatched_equal,
+ NULL, nfs_name_snoop_value_destroy);
+ nfs_name_snoop_matched =
+ g_hash_table_new_full(nfs_name_snoop_matched_hash,
+ nfs_name_snoop_matched_equal,
+ NULL, nfs_name_snoop_value_destroy);
+}
+
+static void
+nfs_name_snoop_cleanup(void)
+{
+ g_hash_table_destroy(nfs_name_snoop_unmatched);
+ g_hash_table_destroy(nfs_name_snoop_matched);
}
@@ -12629,6 +12611,7 @@ proto_register_nfs(void)
nfs_file_handles = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
nfs_fhandle_frame_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
register_init_routine(nfs_name_snoop_init);
+ register_cleanup_routine(nfs_name_snoop_cleanup);
register_decode_as(&nfs_da);
}
diff --git a/epan/dissectors/packet-nlm.c b/epan/dissectors/packet-nlm.c
index c5b80aea66..fa3485fca6 100644
--- a/epan/dissectors/packet-nlm.c
+++ b/epan/dissectors/packet-nlm.c
@@ -112,24 +112,13 @@ typedef struct _nlm_msg_res_matched_data {
nstime_t ns;
} nlm_msg_res_matched_data;
-static gboolean
-nlm_msg_res_unmatched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
+static void
+nlm_msg_res_unmatched_value_destroy(gpointer value)
{
nlm_msg_res_unmatched_data *umd = (nlm_msg_res_unmatched_data *)value;
g_free((gpointer)umd->cookie);
g_free(umd);
-
- return TRUE;
-}
-static gboolean
-nlm_msg_res_matched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
-{
- nlm_msg_res_matched_data *md = (nlm_msg_res_matched_data *)value;
-
- g_free(md);
-
- return TRUE;
}
static guint
@@ -177,21 +166,19 @@ nlm_msg_res_matched_equal(gconstpointer k1, gconstpointer k2)
static void
nlm_msg_res_match_init(void)
{
- if(nlm_msg_res_unmatched != NULL){
- g_hash_table_foreach_remove(nlm_msg_res_unmatched,
- nlm_msg_res_unmatched_free_all, NULL);
- } else {
- nlm_msg_res_unmatched=g_hash_table_new(nlm_msg_res_unmatched_hash,
- nlm_msg_res_unmatched_equal);
- }
+ nlm_msg_res_unmatched =
+ g_hash_table_new_full(nlm_msg_res_unmatched_hash,
+ nlm_msg_res_unmatched_equal,
+ NULL, nlm_msg_res_unmatched_value_destroy);
+ nlm_msg_res_matched = g_hash_table_new_full(nlm_msg_res_matched_hash,
+ nlm_msg_res_matched_equal, NULL, (GDestroyNotify)g_free);
+}
- if(nlm_msg_res_matched != NULL){
- g_hash_table_foreach_remove(nlm_msg_res_matched,
- nlm_msg_res_matched_free_all, NULL);
- } else {
- nlm_msg_res_matched=g_hash_table_new(nlm_msg_res_matched_hash,
- nlm_msg_res_matched_equal);
- }
+static void
+nlm_msg_res_match_cleanup(void)
+{
+ g_hash_table_destroy(nlm_msg_res_unmatched);
+ g_hash_table_destroy(nlm_msg_res_matched);
}
static void
@@ -1221,6 +1208,7 @@ proto_register_nlm(void)
"Whether the dissector will track and match MSG and RES calls for asynchronous NLM",
&nlm_match_msgres);
register_init_routine(nlm_msg_res_match_init);
+ register_cleanup_routine(nlm_msg_res_match_cleanup);
}
void