aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-02-24 19:46:49 -0500
committerMichael Mann <mmann78@netscape.net>2017-02-25 13:35:37 +0000
commit7227728fced5dad3205bf307492e9035453f92da (patch)
tree5e2c449ea4415a8f1db3451dabf8b75c2035d2e4
parent924e6d2b49adf8eee1b13dba0feedadcc531245a (diff)
Convert a few more dissectors to use wmem_hash instead of GHashtable.
Change-Id: I86c9e485b447b380f00195bf407ce28c05bb1822 Reviewed-on: https://code.wireshark.org/review/20268 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--epan/dissectors/packet-dcm.c52
-rw-r--r--epan/dissectors/packet-h223.c16
-rw-r--r--epan/dissectors/packet-nlm.c80
3 files changed, 55 insertions, 93 deletions
diff --git a/epan/dissectors/packet-dcm.c b/epan/dissectors/packet-dcm.c
index dc508241f6..7baaf3f830 100644
--- a/epan/dissectors/packet-dcm.c
+++ b/epan/dissectors/packet-dcm.c
@@ -246,9 +246,9 @@ static gboolean global_dcm_tag_subtree = FALSE; /* Only useful for d
static gboolean global_dcm_cmd_details = TRUE; /* Show details in header and info column */
static gboolean global_dcm_reassemble = TRUE; /* Merge fragmented PDVs */
-static GHashTable *dcm_tag_table = NULL;
-static GHashTable *dcm_uid_table = NULL;
-static GHashTable *dcm_status_table = NULL;
+static wmem_map_t *dcm_tag_table = NULL;
+static wmem_map_t *dcm_uid_table = NULL;
+static wmem_map_t *dcm_status_table = NULL;
/* Initialize the protocol and registered fields */
static int proto_dcm = -1;
@@ -3954,35 +3954,27 @@ dcm_init(void)
/* Create three hash tables for quick lookups */
/* Add UID objects to hash table */
- dcm_uid_table = g_hash_table_new(g_str_hash, g_str_equal);
+ dcm_uid_table = wmem_map_new(wmem_file_scope(), wmem_str_hash, g_str_equal);
for (i = 0; i < array_length(dcm_uid_data); i++) {
- g_hash_table_insert(dcm_uid_table, (gpointer) dcm_uid_data[i].value,
+ wmem_map_insert(dcm_uid_table, (gpointer) dcm_uid_data[i].value,
(gpointer) &dcm_uid_data[i]);
}
/* Add Tag objects to hash table */
- dcm_tag_table = g_hash_table_new(NULL, NULL);
+ dcm_tag_table = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
for (i = 0; i < array_length(dcm_tag_data); i++) {
- g_hash_table_insert(dcm_tag_table, GUINT_TO_POINTER(dcm_tag_data[i].tag),
+ wmem_map_insert(dcm_tag_table, GUINT_TO_POINTER(dcm_tag_data[i].tag),
(gpointer) &dcm_tag_data[i]);
}
/* Add Status Values to hash table */
- dcm_status_table = g_hash_table_new(NULL, NULL);
+ dcm_status_table = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
for (i = 0; i < array_length(dcm_status_data); i++) {
- g_hash_table_insert(dcm_status_table, GUINT_TO_POINTER((guint32)dcm_status_data[i].value),
+ wmem_map_insert(dcm_status_table, GUINT_TO_POINTER((guint32)dcm_status_data[i].value),
(gpointer)&dcm_status_data[i]);
}
}
-static void
-dcm_cleanup(void)
-{
- g_hash_table_destroy(dcm_uid_table);
- g_hash_table_destroy(dcm_tag_table);
- g_hash_table_destroy(dcm_status_table);
-}
-
static dcm_state_t *
dcm_state_get(packet_info *pinfo, gboolean create)
{
@@ -4218,7 +4210,7 @@ dcm_rsp2str(guint16 status_value)
*/
/* Use specific text first */
- status = (dcm_status_t*) g_hash_table_lookup(dcm_status_table, GUINT_TO_POINTER((guint32)status_value));
+ status = (dcm_status_t*) wmem_map_lookup(dcm_status_table, GUINT_TO_POINTER((guint32)status_value));
if (status) {
s = status->description;
@@ -4850,7 +4842,7 @@ dissect_dcm_assoc_item(tvbuff_t *tvb, proto_tree *tree, guint32 offset,
case DCM_ITEM_VALUE_TYPE_UID:
*item_value = (gchar *)tvb_get_string_enc(wmem_packet_scope(), tvb, offset+4, item_len, ENC_ASCII);
- uid = (dcm_uid_t *)g_hash_table_lookup(dcm_uid_table, (gpointer) *item_value);
+ uid = (dcm_uid_t *)wmem_map_lookup(dcm_uid_table, (gpointer) *item_value);
if (uid) {
*item_description = uid->name;
buf_desc = wmem_strdup_printf(wmem_packet_scope(), "%s (%s)", *item_description, *item_value);
@@ -4917,7 +4909,7 @@ dissect_dcm_assoc_sopclass_extneg(tvbuff_t *tvb, proto_tree *tree, guint32 offse
proto_tree_add_item(assoc_item_extneg_tree, hf_dcm_info_extneg_sopclassuid_len, tvb, offset+4, 2, ENC_BIG_ENDIAN);
sopclassuid_str = (gchar *)tvb_get_string_enc(wmem_packet_scope(), tvb, offset+6, sop_class_uid_len, ENC_ASCII);
- sopclassuid = (dcm_uid_t *)g_hash_table_lookup(dcm_uid_table, (gpointer) sopclassuid_str);
+ sopclassuid = (dcm_uid_t *)wmem_map_lookup(dcm_uid_table, (gpointer) sopclassuid_str);
if (sopclassuid) {
buf_desc = wmem_strdup_printf(wmem_packet_scope(), "%s (%s)", sopclassuid->name, sopclassuid->value);
@@ -5019,7 +5011,7 @@ dissect_dcm_assoc_role_selection(tvbuff_t *tvb, proto_tree *tree, guint32 offset
proto_tree_add_item(assoc_item_rolesel_tree, hf_dcm_info_rolesel_sopclassuid_len, tvb, offset+4, 2, ENC_BIG_ENDIAN);
sopclassuid_str = (gchar *)tvb_get_string_enc(wmem_packet_scope(), tvb, offset+6, sop_class_uid_len, ENC_ASCII);
- sopclassuid = (dcm_uid_t *)g_hash_table_lookup(dcm_uid_table, (gpointer) sopclassuid_str);
+ sopclassuid = (dcm_uid_t *)wmem_map_lookup(dcm_uid_table, (gpointer) sopclassuid_str);
scu_role = tvb_get_guint8(tvb, offset+6+sop_class_uid_len);
scp_role = tvb_get_guint8(tvb, offset+7+sop_class_uid_len);
@@ -5656,7 +5648,7 @@ dissect_dcm_tag_value(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, dcm_s
if ((strncmp(vr, "UI", 2) == 0)) {
/* This is a UID. Attempt a lookup. Will only return something for classes of course */
- uid = (dcm_uid_t *)g_hash_table_lookup(dcm_uid_table, (gpointer) vals);
+ uid = (dcm_uid_t *)wmem_map_lookup(dcm_uid_table, (gpointer) vals);
if (uid) {
*tag_value = wmem_strdup_printf(wmem_packet_scope(), "%s (%s)", vals, uid->name);
}
@@ -5893,7 +5885,7 @@ dcm_tag_lookup(guint16 grp, guint16 elm)
static dcm_tag_t tag_grp_length = { 0x00000000, "Group Length", "UL", "1", 0, 0 };
/* Try a direct hit first before doing a masked search */
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | elm));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | elm));
if (tag_def == NULL) {
@@ -5911,23 +5903,23 @@ dcm_tag_lookup(guint16 grp, guint16 elm)
/* There are a few tags that require a mask to be found */
else if (((grp & 0xFF00) == 0x5000) || ((grp & 0xFF00) == 0x6000) || ((grp & 0xFF00) == 0x7F00)) {
/* Do a special for groups 0x50xx, 0x60xx and 0x7Fxx */
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER((((guint32)grp & 0xFF00) << 16) | elm));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER((((guint32)grp & 0xFF00) << 16) | elm));
}
else if ((grp == 0x0020) && ((elm & 0xFF00) == 0x3100)) {
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF00)));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF00)));
}
else if ((grp == 0x0028) && ((elm & 0xFF00) == 0x0400)) {
/* This map was done to 0x041x */
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF0F) | 0x0010));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF0F) | 0x0010));
}
else if ((grp == 0x0028) && ((elm & 0xFF00) == 0x0800)) {
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF0F)));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0xFF0F)));
}
else if (grp == 0x1000) {
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0x000F)));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0x000F)));
}
else if (grp == 0x1010) {
- tag_def = (dcm_tag_t *)g_hash_table_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0x0000)));
+ tag_def = (dcm_tag_t *)wmem_map_lookup(dcm_tag_table, GUINT_TO_POINTER(((guint32)grp << 16) | (elm & 0x0000)));
}
if (tag_def == NULL) {
@@ -7206,7 +7198,7 @@ proto_register_dcm(void)
dicom_eo_tap = register_export_object(proto_dcm, dcm_eo_packet, NULL);
register_init_routine(&dcm_init);
- register_cleanup_routine(&dcm_cleanup);
+
/* Register processing of fragmented DICOM PDVs */
reassembly_table_register(&dcm_pdv_reassembly_table,
&addresses_reassembly_table_functions);
diff --git a/epan/dissectors/packet-h223.c b/epan/dissectors/packet-h223.c
index 756eaac54a..a0ccee759a 100644
--- a/epan/dissectors/packet-h223.c
+++ b/epan/dissectors/packet-h223.c
@@ -178,7 +178,7 @@ typedef struct {
guint32 vc; /* child circuit */
} circuit_chain_key;
-static GHashTable *circuit_chain_hashtable = NULL;
+static wmem_map_t *circuit_chain_hashtable = NULL;
static guint circuit_chain_count = 1;
/* Hash Functions */
@@ -208,12 +208,12 @@ circuit_chain_lookup(const h223_call_info* call_info, guint32 child_vc)
guint32 circuit_id;
key.call = call_info;
key.vc = child_vc;
- circuit_id = GPOINTER_TO_UINT(g_hash_table_lookup( circuit_chain_hashtable, &key ));
+ circuit_id = GPOINTER_TO_UINT(wmem_map_lookup( circuit_chain_hashtable, &key ));
if( circuit_id == 0 ) {
new_key = wmem_new(wmem_file_scope(), circuit_chain_key);
*new_key = key;
circuit_id = ++circuit_chain_count;
- g_hash_table_insert(circuit_chain_hashtable, new_key, GUINT_TO_POINTER(circuit_id));
+ wmem_map_insert(circuit_chain_hashtable, new_key, GUINT_TO_POINTER(circuit_id));
}
return circuit_id;
}
@@ -221,16 +221,9 @@ circuit_chain_lookup(const h223_call_info* call_info, guint32 child_vc)
static void
circuit_chain_init(void)
{
- circuit_chain_hashtable = g_hash_table_new(circuit_chain_hash, circuit_chain_equal);
circuit_chain_count = 1;
}
-static void
-circuit_chain_destroy(void)
-{
- g_hash_table_destroy(circuit_chain_hashtable);
-}
-
/***************************************************************************
*
@@ -1659,7 +1652,8 @@ void proto_register_h223 (void)
/* register our init routine to be called at the start of a capture,
to clear out our hash tables etc */
register_init_routine(&circuit_chain_init);
- register_cleanup_routine(&circuit_chain_destroy);
+
+ circuit_chain_hashtable = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), circuit_chain_hash, circuit_chain_equal);
h245_set_h223_set_mc_handle( &h223_set_mc );
h245_set_h223_add_lc_handle( &h223_add_lc );
diff --git a/epan/dissectors/packet-nlm.c b/epan/dissectors/packet-nlm.c
index ab13baf278..2cfb325ca8 100644
--- a/epan/dissectors/packet-nlm.c
+++ b/epan/dissectors/packet-nlm.c
@@ -92,8 +92,8 @@ static gint ett_nlm_lock = -1;
*/
static gboolean nlm_match_msgres = FALSE;
-static GHashTable *nlm_msg_res_unmatched = NULL;
-static GHashTable *nlm_msg_res_matched = NULL;
+static wmem_map_t *nlm_msg_res_unmatched = NULL;
+static wmem_map_t *nlm_msg_res_matched = NULL;
/* XXX when matching the packets we should really check the conversation (only address
NOT ports) and command type as well. I am lazy and thinks the cookie itself is
@@ -112,15 +112,6 @@ typedef struct _nlm_msg_res_matched_data {
nstime_t ns;
} nlm_msg_res_matched_data;
-static void
-nlm_msg_res_unmatched_value_destroy(gpointer value)
-{
- nlm_msg_res_unmatched_data *umd = (nlm_msg_res_unmatched_data *)value;
-
- wmem_free(NULL, (gpointer)umd->cookie);
- g_free(umd);
-}
-
static guint
nlm_msg_res_unmatched_hash(gconstpointer k)
{
@@ -164,29 +155,11 @@ nlm_msg_res_matched_equal(gconstpointer k1, gconstpointer k2)
}
static void
-nlm_msg_res_match_init(void)
-{
- 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);
-}
-
-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
nlm_print_msgres_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
{
nlm_msg_res_matched_data *md;
- md=(nlm_msg_res_matched_data *)g_hash_table_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
+ md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
if(md){
nstime_t ns;
proto_tree_add_uint(tree, hf_nlm_request_in, tvb, 0, 0, md->req_frame);
@@ -200,7 +173,7 @@ nlm_print_msgres_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
{
nlm_msg_res_matched_data *md;
- md=(nlm_msg_res_matched_data *)g_hash_table_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
+ md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
if(md){
proto_tree_add_uint(tree, hf_nlm_reply_in, tvb, 0, 0, md->rep_frame);
}
@@ -210,7 +183,7 @@ nlm_match_fhandle_reply(packet_info *pinfo, proto_tree *tree)
{
nlm_msg_res_matched_data *md;
- md=(nlm_msg_res_matched_data *)g_hash_table_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
+ md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
if(md && md->rep_frame){
dissect_fhandle_hidden(pinfo,
tree, md->req_frame);
@@ -221,7 +194,7 @@ nlm_match_fhandle_request(packet_info *pinfo, proto_tree *tree)
{
nlm_msg_res_matched_data *md;
- md=(nlm_msg_res_matched_data *)g_hash_table_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
+ md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
if(md && md->rep_frame){
dissect_fhandle_hidden(pinfo,
tree, md->rep_frame);
@@ -238,19 +211,19 @@ nlm_register_unmatched_res(packet_info *pinfo, tvbuff_t *tvb, int offset)
umd.cookie=tvb_get_ptr(tvb, offset+4, -1);
/* have we seen this cookie before? */
- old_umd=(nlm_msg_res_unmatched_data *)g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)&umd);
+ old_umd=(nlm_msg_res_unmatched_data *)wmem_map_lookup(nlm_msg_res_unmatched, (gconstpointer)&umd);
if(old_umd){
nlm_msg_res_matched_data *md_req, *md_rep;
- md_req=(nlm_msg_res_matched_data *)g_malloc(sizeof(nlm_msg_res_matched_data));
- md_req->req_frame=old_umd->req_frame;
- md_req->rep_frame=pinfo->num;
- md_req->ns=old_umd->ns;
- md_rep=(nlm_msg_res_matched_data *)g_memdup(md_req, sizeof(nlm_msg_res_matched_data));
- g_hash_table_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_req->req_frame), (gpointer)md_req);
- g_hash_table_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_rep->rep_frame), (gpointer)md_rep);
+ md_req = wmem_new(wmem_file_scope(), nlm_msg_res_matched_data);
+ md_req->req_frame = old_umd->req_frame;
+ md_req->rep_frame = pinfo->num;
+ md_req->ns = old_umd->ns;
+ md_rep = (nlm_msg_res_matched_data *)wmem_memdup(wmem_file_scope(), md_req, sizeof(nlm_msg_res_matched_data));
+ wmem_map_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_req->req_frame), md_req);
+ wmem_map_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_rep->rep_frame), md_rep);
- g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
+ wmem_map_remove(nlm_msg_res_unmatched, old_umd);
}
}
@@ -261,20 +234,20 @@ nlm_register_unmatched_msg(packet_info *pinfo, tvbuff_t *tvb, int offset)
nlm_msg_res_unmatched_data *old_umd;
/* allocate and build the unmatched structure for this request */
- umd=(nlm_msg_res_unmatched_data *)g_malloc(sizeof(nlm_msg_res_unmatched_data));
- umd->req_frame=pinfo->num;
- umd->ns=pinfo->abs_ts;
- umd->cookie_len=tvb_get_ntohl(tvb, offset);
- umd->cookie=(const guint8 *)tvb_memdup(NULL, tvb, offset+4, umd->cookie_len);
+ umd = wmem_new(wmem_file_scope(), nlm_msg_res_unmatched_data);
+ umd->req_frame = pinfo->num;
+ umd->ns = pinfo->abs_ts;
+ umd->cookie_len = tvb_get_ntohl(tvb, offset);
+ umd->cookie = (const guint8 *)tvb_memdup(wmem_file_scope(), tvb, offset+4, umd->cookie_len);
/* remove any old duplicates */
- old_umd=(nlm_msg_res_unmatched_data *)g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)umd);
+ old_umd=(nlm_msg_res_unmatched_data *)wmem_map_lookup(nlm_msg_res_unmatched, umd);
if(old_umd){
- g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
+ wmem_map_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
}
/* add new one */
- g_hash_table_insert(nlm_msg_res_unmatched, (gpointer)umd, (gpointer)umd);
+ wmem_map_insert(nlm_msg_res_unmatched, umd, umd);
}
@@ -1202,8 +1175,11 @@ proto_register_nlm(void)
"Match MSG/RES packets for async NLM",
"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);
+
+ nlm_msg_res_unmatched = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),
+ nlm_msg_res_unmatched_hash, nlm_msg_res_unmatched_equal);
+ nlm_msg_res_matched = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),
+ nlm_msg_res_matched_hash, nlm_msg_res_matched_equal);
}
void