forked from osmocom/wireshark
Convert some g_ APIs to wmem.
Change-Id: I7fb0b60fc54004326680f07298fe43e8c48e9b39 Reviewed-on: https://code.wireshark.org/review/16550 Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
f7e078cca6
commit
95fa045d38
|
@ -717,25 +717,6 @@ static gboolean get_fid_and_frame(packet_info *pinfo, guint32 *fid, guint *frame
|
|||
return result;
|
||||
}
|
||||
|
||||
static GSList *conv_tables = NULL;
|
||||
|
||||
static void
|
||||
mswsp_init_protocol(void)
|
||||
{
|
||||
GSList *table_iter;
|
||||
if (conv_tables) {
|
||||
for(table_iter = conv_tables; table_iter;
|
||||
table_iter = table_iter->next) {
|
||||
struct mswsp_ct *ct = (struct mswsp_ct *)table_iter->data;
|
||||
/* should we free the elements the GSL_message_data */
|
||||
g_slist_free(ct->GSL_message_data);
|
||||
g_free(ct);
|
||||
}
|
||||
g_slist_free(conv_tables);
|
||||
conv_tables = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct message_data *find_or_create_message_data(struct mswsp_ct *conv_data, packet_info *pinfo, guint16 msg_id, gboolean is_request, void *data)
|
||||
{
|
||||
struct message_data to_find;
|
||||
|
@ -765,20 +746,17 @@ static struct mswsp_ct *get_create_converstation_data(packet_info *pinfo)
|
|||
struct mswsp_ct *ct = NULL;
|
||||
conversation_t *conversation;
|
||||
|
||||
|
||||
conversation = find_or_create_conversation(pinfo);
|
||||
if (!conversation) {
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
ct = (struct mswsp_ct*)conversation_get_proto_data(conversation, proto_mswsp);
|
||||
if (!ct) {
|
||||
ct = (struct mswsp_ct *)g_malloc(sizeof(struct mswsp_ct));
|
||||
ct = wmem_new(wmem_file_scope(), struct mswsp_ct);
|
||||
ct->GSL_message_data = NULL;
|
||||
/* store ct so it can be deallocated later */
|
||||
conv_tables = g_slist_prepend(conv_tables, ct);
|
||||
conversation_add_proto_data(conversation, proto_mswsp, ct);
|
||||
}
|
||||
out:
|
||||
|
||||
return ct;
|
||||
}
|
||||
|
||||
|
@ -8065,9 +8043,6 @@ proto_register_mswsp(void)
|
|||
for (i=0; i<(int)array_length(GuidPropertySet); i++) {
|
||||
guids_add_guid(&GuidPropertySet[i].guid, GuidPropertySet[i].def);
|
||||
}
|
||||
|
||||
register_init_routine(&mswsp_init_protocol);
|
||||
|
||||
}
|
||||
|
||||
static int dissect_mswsp_smb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
||||
|
|
|
@ -444,12 +444,12 @@ get_multipart_info(packet_info *pinfo, const char *str)
|
|||
/*
|
||||
* There is a value for the boundary string
|
||||
*/
|
||||
m_info = (multipart_info_t *)g_malloc(sizeof(multipart_info_t));
|
||||
m_info = wmem_new(wmem_packet_scope(), multipart_info_t);
|
||||
m_info->type = type;
|
||||
m_info->boundary = g_strndup(start_boundary, len_boundary);
|
||||
m_info->boundary = wmem_strndup(wmem_packet_scope(), start_boundary, len_boundary);
|
||||
m_info->boundary_length = len_boundary;
|
||||
if(start_protocol) {
|
||||
m_info->protocol = g_strndup(start_protocol, len_protocol);
|
||||
m_info->protocol = wmem_strndup(wmem_packet_scope(), start_protocol, len_protocol);
|
||||
m_info->protocol_length = len_protocol;
|
||||
} else {
|
||||
m_info->protocol = NULL;
|
||||
|
@ -461,19 +461,6 @@ get_multipart_info(packet_info *pinfo, const char *str)
|
|||
return m_info;
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_multipart_info(void *data)
|
||||
{
|
||||
multipart_info_t *m_info = (multipart_info_t *)data;
|
||||
if (m_info) {
|
||||
if (m_info->protocol) {
|
||||
g_free(m_info->protocol);
|
||||
}
|
||||
g_free(m_info->boundary);
|
||||
g_free(m_info);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The first boundary does not implicitly contain the leading
|
||||
* line-end sequence.
|
||||
|
@ -622,10 +609,8 @@ dissect_kerberos_encrypted_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree
|
|||
|
||||
DISSECTOR_ASSERT(tvb_bytes_exist(tvb, offset, len));
|
||||
|
||||
data = (guint8 *) g_malloc(len);
|
||||
tvb_memcpy(tvb, data, offset, len);
|
||||
data = (guint8 *)tvb_memdup(pinfo->pool, tvb, offset, len);
|
||||
kerberos_tvb = tvb_new_child_real_data(tvb, data, len, len);
|
||||
tvb_set_free_cb(kerberos_tvb, g_free);
|
||||
|
||||
add_new_data_source(pinfo, kerberos_tvb, "Kerberos Data");
|
||||
call_dissector_with_data(gssapi_handle, kerberos_tvb, pinfo, tree, encrypt);
|
||||
|
@ -936,8 +921,6 @@ static int dissect_multipart(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
|
|||
call_data_dissector(tvb, pinfo, tree);
|
||||
return tvb_reported_length(tvb);
|
||||
}
|
||||
/* Clean up the memory if an exception is thrown */
|
||||
/* CLEANUP_PUSH(cleanup_multipart_info, m_info); */
|
||||
|
||||
/* Add stuff to the protocol tree */
|
||||
ti = proto_tree_add_item(tree, proto_multipart,
|
||||
|
@ -963,8 +946,6 @@ static int dissect_multipart(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
|
|||
header_start = process_preamble(subtree, tvb, m_info, &last_boundary);
|
||||
if (header_start == -1) {
|
||||
call_data_dissector(tvb, pinfo, subtree);
|
||||
/* Clean up the dynamically allocated memory */
|
||||
cleanup_multipart_info(m_info);
|
||||
return tvb_reported_length(tvb);
|
||||
}
|
||||
/*
|
||||
|
@ -974,8 +955,6 @@ static int dissect_multipart(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
|
|||
header_start = process_body_part(subtree, tvb, m_info,
|
||||
pinfo, header_start, body_index++, &last_boundary);
|
||||
if (header_start == -1) {
|
||||
/* Clean up the dynamically allocated memory */
|
||||
cleanup_multipart_info(m_info);
|
||||
return tvb_reported_length(tvb);
|
||||
}
|
||||
}
|
||||
|
@ -985,8 +964,7 @@ static int dissect_multipart(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
|
|||
if (tvb_reported_length_remaining(tvb, header_start) > 0) {
|
||||
proto_tree_add_item(subtree, hf_multipart_trailer, tvb, header_start, -1, ENC_NA);
|
||||
}
|
||||
/* Clean up the dynamically allocated memory */
|
||||
cleanup_multipart_info(m_info);
|
||||
|
||||
return tvb_reported_length(tvb);
|
||||
}
|
||||
|
||||
|
|
|
@ -450,23 +450,18 @@ static const value_string packettypenames_creds[]= {
|
|||
};
|
||||
|
||||
typedef struct pcp_conv_info_t {
|
||||
struct pcp_conv_info_t *next;
|
||||
GArray *pmid_name_candidates;
|
||||
GHashTable *pmid_to_name;
|
||||
wmem_array_t *pmid_name_candidates;
|
||||
wmem_map_t *pmid_to_name;
|
||||
guint32 last_pmns_names_frame;
|
||||
guint32 last_processed_pmns_names_frame;
|
||||
} pcp_conv_info_t;
|
||||
|
||||
static pcp_conv_info_t *pcp_conv_info_items = NULL;
|
||||
|
||||
/* function prototypes */
|
||||
static void pcp_cleanup(void);
|
||||
static pcp_conv_info_t* get_pcp_conversation_info(packet_info *pinfo);
|
||||
static int is_unvisited_pmns_names_frame(packet_info *pinfo);
|
||||
static void add_candidate_name_for_pmid_resolution(packet_info *pinfo, tvbuff_t *tvb, int offset, int name_len);
|
||||
static void mark_this_frame_as_last_pmns_names_frame(packet_info *pinfo);
|
||||
static inline int has_unprocessed_pmns_names_frame(pcp_conv_info_t *pcp_conv_info);
|
||||
static void clear_name_candidates(GArray *pmid_name_candidates);
|
||||
static void create_pmid_to_name_map_from_candidates(pcp_conv_info_t *pcp_conv_info, tvbuff_t *tvb, int offset, guint32 num_ids);
|
||||
static void populate_pmids_to_names(packet_info *pinfo, tvbuff_t *tvb, int offset, guint32 num_ids);
|
||||
static inline int client_to_server(packet_info *pinfo);
|
||||
|
@ -519,19 +514,13 @@ static inline int client_to_server(packet_info *pinfo) {
|
|||
return pinfo->destport == PCP_PORT || pinfo->destport == PMPROXY_PORT;
|
||||
}
|
||||
|
||||
static void clear_name_candidates(GArray *pmid_name_candidates) {
|
||||
if(pmid_name_candidates->len > 0) {
|
||||
g_array_remove_range(pmid_name_candidates, 0, pmid_name_candidates->len);
|
||||
}
|
||||
}
|
||||
|
||||
static guint8* get_name_from_pmid(guint32 pmid, packet_info *pinfo) {
|
||||
guint8 *name;
|
||||
GHashTable *pmid_to_name;
|
||||
wmem_map_t *pmid_to_name;
|
||||
|
||||
pmid_to_name = get_pcp_conversation_info(pinfo)->pmid_to_name;
|
||||
|
||||
name = (guint8*)g_hash_table_lookup(pmid_to_name, GINT_TO_POINTER(pmid));
|
||||
name = (guint8*)wmem_map_lookup(pmid_to_name, GINT_TO_POINTER(pmid));
|
||||
if(!name) {
|
||||
name = (guint8*)wmem_strdup(wmem_packet_scope(), "Metric name unknown");
|
||||
}
|
||||
|
@ -592,7 +581,7 @@ static void add_candidate_name_for_pmid_resolution(packet_info *pinfo, tvbuff_t
|
|||
|
||||
if(is_unvisited_pmns_names_frame(pinfo)) {
|
||||
name = tvb_get_string_enc(wmem_file_scope(), tvb, offset, name_len, ENC_ASCII);
|
||||
g_array_append_val(pcp_conv_info->pmid_name_candidates, name);
|
||||
wmem_array_append_one(pcp_conv_info->pmid_name_candidates, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -609,14 +598,15 @@ static void populate_pmids_to_names(packet_info *pinfo, tvbuff_t *tvb, int offse
|
|||
guint number_of_name_candidates;
|
||||
|
||||
pcp_conv_info = get_pcp_conversation_info(pinfo);
|
||||
number_of_name_candidates = pcp_conv_info->pmid_name_candidates->len;
|
||||
number_of_name_candidates = wmem_array_get_count(pcp_conv_info->pmid_name_candidates);
|
||||
|
||||
if(number_of_name_candidates == num_ids && has_unprocessed_pmns_names_frame(pcp_conv_info)) {
|
||||
create_pmid_to_name_map_from_candidates(pcp_conv_info, tvb, offset, num_ids);
|
||||
/* Set this frame to the one that we processed */
|
||||
pcp_conv_info->last_processed_pmns_names_frame = pcp_conv_info->last_pmns_names_frame;
|
||||
}
|
||||
clear_name_candidates(pcp_conv_info->pmid_name_candidates);
|
||||
|
||||
pcp_conv_info->pmid_name_candidates = wmem_array_new(wmem_file_scope(), sizeof(guint8 *));
|
||||
}
|
||||
|
||||
static void create_pmid_to_name_map_from_candidates(pcp_conv_info_t *pcp_conv_info, tvbuff_t *tvb, int offset, guint32 num_ids) {
|
||||
|
@ -627,10 +617,10 @@ static void create_pmid_to_name_map_from_candidates(pcp_conv_info_t *pcp_conv_in
|
|||
guint8 *pmid_name;
|
||||
|
||||
pmid = tvb_get_ntohl(tvb, offset);
|
||||
pmid_name = g_array_index(pcp_conv_info->pmid_name_candidates, guint8*, i);
|
||||
pmid_name = wmem_array_index(pcp_conv_info->pmid_name_candidates, i);
|
||||
|
||||
if(g_hash_table_lookup(pcp_conv_info->pmid_to_name, GINT_TO_POINTER(pmid)) == NULL) {
|
||||
g_hash_table_insert(pcp_conv_info->pmid_to_name, GINT_TO_POINTER(pmid), pmid_name);
|
||||
if(wmem_map_lookup(pcp_conv_info->pmid_to_name, GINT_TO_POINTER(pmid)) == NULL) {
|
||||
wmem_map_insert(pcp_conv_info->pmid_to_name, GINT_TO_POINTER(pmid), pmid_name);
|
||||
}
|
||||
offset += 4;
|
||||
}
|
||||
|
@ -687,7 +677,7 @@ static int dissect_pcp_message_error(tvbuff_t *tvb, packet_info *pinfo, proto_tr
|
|||
*/
|
||||
if(error_num == PM_ERR_NAME) {
|
||||
pcp_conv_info = get_pcp_conversation_info(pinfo);
|
||||
clear_name_candidates(pcp_conv_info->pmid_name_candidates);
|
||||
pcp_conv_info->pmid_name_candidates = wmem_array_new(wmem_file_scope(), sizeof(guint8 *));
|
||||
}
|
||||
|
||||
return offset;
|
||||
|
@ -1641,13 +1631,10 @@ static int dissect_pcp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tr
|
|||
pcp_conv_info = (pcp_conv_info_t*)g_malloc(sizeof(pcp_conv_info_t));
|
||||
conversation_add_proto_data(conversation, proto_pcp, pcp_conv_info);
|
||||
|
||||
pcp_conv_info->pmid_name_candidates = g_array_new(TRUE, TRUE, sizeof(guint8 *));
|
||||
pcp_conv_info->pmid_to_name = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
pcp_conv_info->pmid_name_candidates = wmem_array_new(wmem_file_scope(), sizeof(guint8 *));
|
||||
pcp_conv_info->pmid_to_name = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
|
||||
pcp_conv_info->last_pmns_names_frame = 0;
|
||||
pcp_conv_info->last_processed_pmns_names_frame = 0;
|
||||
|
||||
pcp_conv_info->next = pcp_conv_info_items;
|
||||
pcp_conv_info_items = pcp_conv_info;
|
||||
}
|
||||
|
||||
root_pcp_item = proto_tree_add_item(tree, proto_pcp, tvb, 0, -1, ENC_NA);
|
||||
|
@ -1762,23 +1749,6 @@ static int dissect_pcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void
|
|||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
static void pcp_cleanup(void) {
|
||||
pcp_conv_info_t *pcp_conv_info;
|
||||
|
||||
for(pcp_conv_info = pcp_conv_info_items; pcp_conv_info != NULL; ) {
|
||||
pcp_conv_info_t *last;
|
||||
|
||||
g_hash_table_destroy(pcp_conv_info->pmid_to_name);
|
||||
/* Don't free array elements (FALSE arg) as their memory is controlled via wmem */
|
||||
g_array_free(pcp_conv_info->pmid_name_candidates, FALSE);
|
||||
|
||||
last = pcp_conv_info;
|
||||
pcp_conv_info = pcp_conv_info->next;
|
||||
|
||||
g_free(last);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup the dissecting */
|
||||
void proto_register_pcp(void)
|
||||
{
|
||||
|
@ -2587,8 +2557,6 @@ void proto_register_pcp(void)
|
|||
proto_register_subtree_array(ett, array_length(ett));
|
||||
|
||||
pcp_handle = register_dissector("pcp", dissect_pcp, proto_pcp);
|
||||
|
||||
register_cleanup_routine(pcp_cleanup);
|
||||
}
|
||||
|
||||
void proto_reg_handoff_pcp(void)
|
||||
|
|
Loading…
Reference in New Issue