diff options
author | Moshe Kaplan <me@moshekaplan.com> | 2020-12-20 21:30:28 -0500 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2020-12-22 14:56:38 +0000 |
commit | e16166a74cca1d66e2c302e257cf94aebb380599 (patch) | |
tree | 8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e /epan/dissectors | |
parent | 7b27b444cbd94853b399da770e0dad4b91ef23ac (diff) |
Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows
Also fixes all existing occurrences across
the codebase.
Diffstat (limited to 'epan/dissectors')
34 files changed, 109 insertions, 127 deletions
diff --git a/epan/dissectors/packet-batadv.c b/epan/dissectors/packet-batadv.c index 01483fda20..a1c4bea020 100644 --- a/epan/dissectors/packet-batadv.c +++ b/epan/dissectors/packet-batadv.c @@ -1121,7 +1121,7 @@ static int dissect_batadv_batman_v5(tvbuff_t *tvb, int offset, packet_info *pinf tvbuff_t *next_tvb; - batman_packeth = (struct batman_packet_v5 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v5)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v5); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1216,7 +1216,7 @@ static int dissect_batadv_batman_v7(tvbuff_t *tvb, int offset, packet_info *pinf tvbuff_t *next_tvb; - batman_packeth = (struct batman_packet_v7 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v7)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v7); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1301,7 +1301,7 @@ static int dissect_batadv_batman_v9(tvbuff_t *tvb, int offset, packet_info *pinf tvbuff_t *next_tvb; - batman_packeth = (struct batman_packet_v9 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v9)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v9); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1394,7 +1394,7 @@ static int dissect_batadv_batman_v10(tvbuff_t *tvb, int offset, packet_info *pin tvbuff_t *next_tvb; - batman_packeth = (struct batman_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v10)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v10); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1487,7 +1487,7 @@ static int dissect_batadv_batman_v11(tvbuff_t *tvb, int offset, packet_info *pin tvbuff_t *next_tvb; - batman_packeth = (struct batman_packet_v11 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v11)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v11); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1573,7 +1573,7 @@ static int dissect_batadv_batman_v14(tvbuff_t *tvb, int offset, packet_info *pin tvbuff_t *next_tvb; gint length_remaining; - batman_packeth = (struct batman_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v14)); + batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v14); type = tvb_get_guint8(tvb, offset+0); batman_packeth->version = tvb_get_guint8(tvb, offset+1); @@ -1712,8 +1712,7 @@ static int dissect_batadv_iv_ogm_v15(tvbuff_t *tvb, int offset, if (version == 0 || type != BATADV_IV_OGM_V15) return -1; - iv_ogm_packeth = (struct iv_ogm_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct iv_ogm_packet_v15)); + iv_ogm_packeth = wmem_new(wmem_packet_scope(), struct iv_ogm_packet_v15); /* Set info column */ col_clear(pinfo->cinfo, COL_INFO); @@ -1856,7 +1855,7 @@ static void dissect_batadv_bcast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tre proto_tree *batadv_bcast_tree; proto_item *ti; - bcast_packeth = (struct bcast_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v6)); + bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v6); bcast_packeth->version = tvb_get_guint8(tvb, 1); set_address_tvb(&bcast_packeth->orig, AT_ETHER, 6, tvb, 2); @@ -1910,7 +1909,7 @@ static void dissect_batadv_bcast_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tr proto_tree *batadv_bcast_tree; proto_item *ti; - bcast_packeth = (struct bcast_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v10)); + bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v10); bcast_packeth->version = tvb_get_guint8(tvb, 1); set_address_tvb(&bcast_packeth->orig, AT_ETHER, 6, tvb, 2); @@ -1969,7 +1968,7 @@ static void dissect_batadv_bcast_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tr proto_tree *batadv_bcast_tree; proto_item *ti; - bcast_packeth = (struct bcast_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v14)); + bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v14); bcast_packeth->packet_type = tvb_get_guint8(tvb, 0); bcast_packeth->version = tvb_get_guint8(tvb, 1); @@ -2069,7 +2068,7 @@ static void dissect_batadv_icmp_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree proto_tree *batadv_icmp_tree; proto_item *ti; - icmp_packeth = (struct icmp_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v6)); + icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v6); icmp_packeth->version = tvb_get_guint8(tvb, 1); icmp_packeth->msg_type = tvb_get_guint8(tvb, 2); @@ -2192,7 +2191,7 @@ static void dissect_batadv_icmp_v7(tvbuff_t *tvb, packet_info *pinfo, proto_tree gint length_remaining; int offset = 0; - icmp_packeth = (struct icmp_packet_v7 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v7)); + icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v7); icmp_packeth->version = tvb_get_guint8(tvb, 1); icmp_packeth->msg_type = tvb_get_guint8(tvb, 2); @@ -2272,7 +2271,7 @@ static void dissect_batadv_icmp_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tre gint length_remaining; int offset = 0; - icmp_packeth = (struct icmp_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v14)); + icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v14); icmp_packeth->version = tvb_get_guint8(tvb, 1); icmp_packeth->ttl = tvb_get_guint8(tvb, 2); @@ -2358,8 +2357,7 @@ static void dissect_batadv_icmp_tp_v15(tvbuff_t *tvb, packet_info *pinfo, guint32 msg_type; int offset = 0; - icmp_packeth = (struct icmp_tp_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct icmp_tp_packet_v15)); + icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_tp_packet_v15); /* Set info column */ col_clear(pinfo->cinfo, COL_INFO); @@ -2462,8 +2460,7 @@ static void dissect_batadv_icmp_simple_v15(tvbuff_t *tvb, packet_info *pinfo, int offset = 0; guint32 seqno; - icmp_packeth = (struct icmp_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct icmp_packet_v15)); + icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v15); /* Set info column */ col_clear(pinfo->cinfo, COL_INFO); @@ -2607,7 +2604,7 @@ static void dissect_batadv_unicast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_t proto_tree *batadv_unicast_tree; proto_item *ti; - unicast_packeth = (struct unicast_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_packet_v6)); + unicast_packeth = wmem_new(wmem_packet_scope(), struct unicast_packet_v6); unicast_packeth->version = tvb_get_guint8(tvb, 1); set_address_tvb(&unicast_packeth->dest, AT_ETHER, 6, tvb, 2); @@ -2663,7 +2660,7 @@ static void dissect_batadv_unicast_v14(tvbuff_t *tvb, packet_info *pinfo, proto_ proto_tree *batadv_unicast_tree; proto_item *ti; - unicast_packeth = (struct unicast_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_packet_v14)); + unicast_packeth = wmem_new(wmem_packet_scope(), struct unicast_packet_v14); unicast_packeth->packet_type = tvb_get_guint8(tvb, 0); unicast_packeth->version = tvb_get_guint8(tvb, 1); @@ -2747,7 +2744,7 @@ static void dissect_batadv_unicast_4addr_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tree *batadv_unicast_4addr_tree; proto_item *ti; - unicast_4addr_packeth = (struct unicast_4addr_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_4addr_packet_v14)); + unicast_4addr_packeth = wmem_new(wmem_packet_scope(), struct unicast_4addr_packet_v14); unicast_4addr_packeth->packet_type = tvb_get_guint8(tvb, 0); unicast_4addr_packeth->version = tvb_get_guint8(tvb, 1); @@ -2855,7 +2852,7 @@ static void dissect_batadv_unicast_frag_v12(tvbuff_t *tvb, packet_info *pinfo, p int head = 0; gint length_remaining; - unicast_frag_packeth = (struct unicast_frag_packet_v12 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_frag_packet_v12)); + unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v12); unicast_frag_packeth->version = tvb_get_guint8(tvb, 1); set_address_tvb(&unicast_frag_packeth->dest, AT_ETHER, 6, tvb, 2); @@ -2944,7 +2941,7 @@ static void dissect_batadv_unicast_frag_v14(tvbuff_t *tvb, packet_info *pinfo, p int head = 0; gint length_remaining; - unicast_frag_packeth = (struct unicast_frag_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_frag_packet_v14)); + unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v14); unicast_frag_packeth->version = tvb_get_guint8(tvb, 1); unicast_frag_packeth->ttl = tvb_get_guint8(tvb, 2); @@ -3042,8 +3039,7 @@ static void dissect_batadv_unicast_frag_v15(tvbuff_t *tvb, packet_info *pinfo, int frag_no = 0; gint length_remaining; - unicast_frag_packeth = (struct unicast_frag_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct unicast_frag_packet_v15)); + unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v15); save_fragmented = pinfo->fragmented; pinfo->fragmented = TRUE; @@ -3191,7 +3187,7 @@ static void dissect_batadv_vis_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree gint length_remaining; int offset = 0, i; - vis_packeth = (struct vis_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v6)); + vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v6); vis_packeth->version = tvb_get_guint8(tvb, 1); vis_packeth->vis_type = tvb_get_guint8(tvb, 2); @@ -3307,7 +3303,7 @@ static void dissect_batadv_vis_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree gint length_remaining; int offset = 0, i; - vis_packeth = (struct vis_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v10)); + vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v10); vis_packeth->version = tvb_get_guint8(tvb, 1); vis_packeth->vis_type = tvb_get_guint8(tvb, 2); @@ -3399,7 +3395,7 @@ static void dissect_batadv_vis_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tree gint length_remaining; int offset = 0, i; - vis_packeth = (struct vis_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v14)); + vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v14); vis_packeth->version = tvb_get_guint8(tvb, 1); vis_packeth->ttl = tvb_get_guint8(tvb, 2); @@ -3543,7 +3539,7 @@ static void dissect_batadv_tt_query_v14(tvbuff_t *tvb, packet_info *pinfo, proto int offset = 0, i; int tt_type; - tt_query_packeth = (struct tt_query_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct tt_query_packet_v14)); + tt_query_packeth = wmem_new(wmem_packet_scope(), struct tt_query_packet_v14); tt_query_packeth->version = tvb_get_guint8(tvb, 1); tt_query_packeth->ttl = tvb_get_guint8(tvb, 2); @@ -3688,7 +3684,7 @@ static void dissect_batadv_roam_adv_v14(tvbuff_t *tvb, packet_info *pinfo, proto gint length_remaining; int offset = 0; - roam_adv_packeth = (struct roam_adv_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct roam_adv_packet_v14)); + roam_adv_packeth = wmem_new(wmem_packet_scope(), struct roam_adv_packet_v14); roam_adv_packeth->version = tvb_get_guint8(tvb, 1); roam_adv_packeth->ttl = tvb_get_guint8(tvb, 2); @@ -3776,8 +3772,7 @@ static void dissect_batadv_coded_v15(tvbuff_t *tvb, packet_info *pinfo, gint length_remaining; int offset = 0; - coded_packeth = (struct coded_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct coded_packet_v15)); + coded_packeth = wmem_new(wmem_packet_scope(), struct coded_packet_v15); /* Set tree info */ ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, @@ -3911,8 +3906,7 @@ static void dissect_batadv_elp_v15(tvbuff_t *tvb, packet_info *pinfo, gint length_remaining; int offset = 0; - elp_packeth = (struct elp_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct elp_packet_v15)); + elp_packeth = wmem_new(wmem_packet_scope(), struct elp_packet_v15); /* Set tree info */ ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, @@ -4009,8 +4003,7 @@ static int dissect_batadv_ogm2_v15(tvbuff_t *tvb, int offset, if (version == 0 || type != BATADV_OGM2_V15) return -1; - ogm2_packeth = (struct ogm2_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct ogm2_packet_v15)); + ogm2_packeth = wmem_new(wmem_packet_scope(), struct ogm2_packet_v15); /* Set tree info */ ogm2_packeth->tvlv_len = tvb_get_ntohs(tvb, 16); @@ -4120,8 +4113,7 @@ static void dissect_batadv_unicast_tvlv_v15(tvbuff_t *tvb, packet_info *pinfo, proto_tree *batadv_unicast_tvlv_tree; proto_item *ti; - unicast_tvlv_packeth = (struct unicast_tvlv_packet_v15 *)wmem_alloc(wmem_packet_scope(), - sizeof(struct unicast_tvlv_packet_v15)); + unicast_tvlv_packeth = wmem_new(wmem_packet_scope(), struct unicast_tvlv_packet_v15); /* Set info column */ col_clear(pinfo->cinfo, COL_INFO); diff --git a/epan/dissectors/packet-btmesh.c b/epan/dissectors/packet-btmesh.c index f1562a2ed3..124faf86f8 100644 --- a/epan/dissectors/packet-btmesh.c +++ b/epan/dissectors/packet-btmesh.c @@ -3630,10 +3630,10 @@ uat_btmesh_record_update_cb(void *r, char **err _U_) g_free(rec->network_key); rec->network_key_length = compute_ascii_key(&rec->network_key, rec->network_key_string); g_free(rec->encryptionkey); - rec->encryptionkey = (guint8 *)g_malloc(16 * sizeof(guint8)); + rec->encryptionkey = g_new(guint8, 16); memset(rec->encryptionkey, 0, 16 * sizeof(guint8)); g_free(rec->privacykey); - rec->privacykey = (guint8 *)g_malloc(16 * sizeof(guint8)); + rec->privacykey = g_new(guint8, 16); if (create_master_security_keys(rec)) { rec->valid++; } diff --git a/epan/dissectors/packet-dbus.c b/epan/dissectors/packet-dbus.c index 4fd951c90f..a6a3d33fa7 100644 --- a/epan/dissectors/packet-dbus.c +++ b/epan/dissectors/packet-dbus.c @@ -698,8 +698,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) { is_single_complete_type = TRUE; } else if (array_len <= DBUS_MAX_ARRAY_LEN) { int end_offset = ptvcursor_current_offset(packet->cursor) + array_len; - dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc( - wmem_packet_scope(), sizeof(dbus_type_reader_t)); + dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t); *child = (dbus_type_reader_t){ .packet = reader->packet, .signature = reader->signature, @@ -722,8 +721,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) { is_single_complete_type = FALSE; ptvcursor_add_with_subtree(packet->cursor, hf != -1 ? hf : hf_dbus_type_struct, SUBTREE_UNDEFINED_LENGTH, ENC_NA, ett != -1 ? ett : ett_dbus_type_struct); - dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc( - wmem_packet_scope(), sizeof(dbus_type_reader_t)); + dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t); *child = (dbus_type_reader_t){ .packet = reader->packet, .signature = reader->signature, @@ -742,8 +740,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) { const char *variant_signature = add_dbus_string(packet, hf_dbus_type_variant_signature, 1); value->string = variant_signature; if (variant_signature && is_dbus_signature_valid(variant_signature)) { - dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc( - wmem_packet_scope(), sizeof(dbus_type_reader_t)); + dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t); *child = (dbus_type_reader_t){ .packet = reader->packet, .signature = variant_signature, @@ -770,8 +767,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) { proto_item *dict_entry = ptvcursor_add_with_subtree(packet->cursor, hf != -1 ? hf : hf_dbus_type_dict_entry, SUBTREE_UNDEFINED_LENGTH, ENC_NA, ett != -1 ? ett : ett_dbus_type_dict_entry); - dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc( - wmem_packet_scope(), sizeof(dbus_type_reader_t)); + dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t); *child = (dbus_type_reader_t){ .packet = reader->packet, .signature = reader->signature, diff --git a/epan/dissectors/packet-dcerpc.c b/epan/dissectors/packet-dcerpc.c index a57b2849eb..a37c51b69c 100644 --- a/epan/dissectors/packet-dcerpc.c +++ b/epan/dissectors/packet-dcerpc.c @@ -778,7 +778,7 @@ dcerpc_add_conv_to_bind_table(decode_dcerpc_bind_values_t *binding) 0); } - bind_value = (dcerpc_bind_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_value)); + bind_value = wmem_new(wmem_file_scope(), dcerpc_bind_value); bind_value->uuid = binding->uuid; bind_value->ver = binding->ver; /* For now, assume all DCE/RPC we pick from "decode as" is using @@ -787,7 +787,7 @@ dcerpc_add_conv_to_bind_table(decode_dcerpc_bind_values_t *binding) */ bind_value->transport = uuid_data_repr_proto; - key = (dcerpc_bind_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_key)); + key = wmem_new(wmem_file_scope(), dcerpc_bind_key); key->conv = conv; key->ctx_id = binding->ctx_id; key->transport_salt = binding->transport_salt; @@ -1195,7 +1195,7 @@ void register_dcerpc_auth_subdissector(guint8 auth_level, guint8 auth_type, if (get_auth_subdissector_fns(auth_level, auth_type)) return; - d = (dcerpc_auth_subdissector *)g_malloc(sizeof(dcerpc_auth_subdissector)); + d = g_new(dcerpc_auth_subdissector, 1); d->auth_level = auth_level; d->auth_type = auth_type; @@ -3172,7 +3172,7 @@ add_pointer_to_list(packet_info *pinfo, proto_tree *tree, proto_item *item, } } - npd = (ndr_pointer_data_t *)g_malloc(sizeof(ndr_pointer_data_t)); + npd = g_new(ndr_pointer_data_t, 1); npd->id = id; npd->tree = tree; npd->item = item; @@ -3803,7 +3803,7 @@ static dcerpc_auth_context *find_or_create_dcerpc_auth_context(packet_info *pinf goto return_value; } - auth_value = (dcerpc_auth_context *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_auth_context)); + auth_value = wmem_new(wmem_file_scope(), dcerpc_auth_context); if (auth_value == NULL) { return NULL; } @@ -4155,12 +4155,12 @@ dissect_dcerpc_cn_bind(tvbuff_t *tvb, gint offset, packet_info *pinfo, dcerpc_bind_key *key; dcerpc_bind_value *value; - key = (dcerpc_bind_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_key)); + key = wmem_new(wmem_file_scope(), dcerpc_bind_key); key->conv = conv; key->ctx_id = ctx_id; key->transport_salt = dcerpc_get_transport_salt(pinfo); - value = (dcerpc_bind_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_value)); + value = wmem_new(wmem_file_scope(), dcerpc_bind_value); value->uuid = if_id; value->ver = if_ver; value->transport = trans_id; @@ -4636,7 +4636,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo, call_key.call_id = hdr->call_id; call_key.transport_salt = dcerpc_get_transport_salt(pinfo); if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_cn_calls, &call_key))) { - new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key)); + new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key); *new_matched_key = matched_key; wmem_map_insert(dcerpc_matched, new_matched_key, call_value); value = call_value; @@ -4650,7 +4650,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo, the call to both the call table and the matched table */ - call_key = (dcerpc_cn_call_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_cn_call_key)); + call_key = wmem_new(wmem_file_scope(), dcerpc_cn_call_key); call_key->conv = conv; call_key->call_id = hdr->call_id; call_key->transport_salt = dcerpc_get_transport_salt(pinfo); @@ -4661,7 +4661,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo, wmem_map_remove(dcerpc_cn_calls, call_key); } - call_value = (dcerpc_call_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_call_value)); + call_value = wmem_new(wmem_file_scope(), dcerpc_call_value); call_value->uuid = bind_value->uuid; call_value->ver = bind_value->ver; call_value->object_uuid = obj_id; @@ -4680,7 +4680,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo, wmem_map_insert(dcerpc_cn_calls, call_key, call_value); - new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key)); + new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key); *new_matched_key = matched_key; wmem_map_insert(dcerpc_matched, new_matched_key, call_value); value = call_value; @@ -4796,7 +4796,7 @@ dissect_dcerpc_cn_resp(tvbuff_t *tvb, gint offset, packet_info *pinfo, /* extra sanity check, only match them if the reply came after the request */ if (call_value->req_frame<pinfo->num) { - new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key)); + new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key); *new_matched_key = matched_key; wmem_map_insert(dcerpc_matched, new_matched_key, call_value); value = call_value; @@ -4960,7 +4960,7 @@ dissect_dcerpc_cn_fault(tvbuff_t *tvb, gint offset, packet_info *pinfo, call_key.transport_salt = dcerpc_get_transport_salt(pinfo); if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_cn_calls, &call_key))) { - new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key)); + new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key); *new_matched_key = matched_key; wmem_map_insert(dcerpc_matched, new_matched_key, call_value); @@ -6207,12 +6207,12 @@ dissect_dcerpc_dg_rqst(tvbuff_t *tvb, int offset, packet_info *pinfo, dcerpc_call_value *call_value; dcerpc_dg_call_key *call_key; - call_key = (dcerpc_dg_call_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_dg_call_key)); + call_key = wmem_new(wmem_file_scope(), dcerpc_dg_call_key); call_key->conv = conv; call_key->seqnum = hdr->seqnum; call_key->act_id = hdr->act_id; - call_value = (dcerpc_call_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_call_value)); + call_value = wmem_new(wmem_file_scope(), dcerpc_call_value); call_value->uuid = hdr->if_id; call_value->ver = hdr->if_ver; call_value->object_uuid = hdr->obj_id; @@ -6291,7 +6291,7 @@ dissect_dcerpc_dg_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, call_key.act_id = hdr->act_id; if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_dg_calls, &call_key))) { - new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key)); + new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key); new_matched_key->frame = pinfo->num; new_matched_key->call_id = hdr->seqnum; wmem_map_insert(dcerpc_matched, new_matched_key, call_value); diff --git a/epan/dissectors/packet-dpaux.c b/epan/dissectors/packet-dpaux.c index 53cce1539d..4d4e1c0d0e 100644 --- a/epan/dissectors/packet-dpaux.c +++ b/epan/dissectors/packet-dpaux.c @@ -179,8 +179,7 @@ dissect_dpaux_from_source(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) conversation = conversation_new(pinfo->num, &pinfo->src, &pinfo->dst, ENDPOINT_NONE, pinfo->srcport, pinfo->destport, 0); - transaction = (struct dpaux_transaction*)wmem_alloc(wmem_file_scope(), - sizeof(struct dpaux_transaction)); + transaction = wmem_new(wmem_file_scope(), struct dpaux_transaction); transaction->is_native = type; transaction->addr = addr; diff --git a/epan/dissectors/packet-exported_pdu.c b/epan/dissectors/packet-exported_pdu.c index 540fae45fa..490e4b3e7e 100644 --- a/epan/dissectors/packet-exported_pdu.c +++ b/epan/dissectors/packet-exported_pdu.c @@ -266,7 +266,7 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* break; case EXP_PDU_TAG_SS7_OPC: proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_opc, tvb, offset, 4, ENC_BIG_ENDIAN); - mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t)); + mtp3_addr = wmem_new0(pinfo->pool, mtp3_addr_pc_t); mtp3_addr->pc = tvb_get_ntohl(tvb, offset); mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4); mtp3_addr->ni = tvb_get_guint8(tvb, offset+6); @@ -274,7 +274,7 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* break; case EXP_PDU_TAG_SS7_DPC: proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_dpc, tvb, offset, 4, ENC_BIG_ENDIAN); - mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t)); + mtp3_addr = wmem_new0(pinfo->pool, mtp3_addr_pc_t); mtp3_addr->pc = tvb_get_ntohl(tvb, offset); mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4); mtp3_addr->ni = tvb_get_guint8(tvb, offset+6); diff --git a/epan/dissectors/packet-fpp.c b/epan/dissectors/packet-fpp.c index dd9514520d..25a0443551 100644 --- a/epan/dissectors/packet-fpp.c +++ b/epan/dissectors/packet-fpp.c @@ -368,7 +368,7 @@ dissect_preemption(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 if (!PINFO_FD_VISITED(pinfo)) { // Fist delete previous conversation drop_conversation(conv); - ctx = (struct _fpp_ctx_t *)wmem_alloc(wmem_file_scope(), sizeof(struct _fpp_ctx_t)); + ctx = wmem_new(wmem_file_scope(), struct _fpp_ctx_t); init_fpp_ctx(ctx, get_cont_by_start(smd2)); ctx->size = frag_size; conversation_add_proto_data(conv, proto_fpp, ctx); diff --git a/epan/dissectors/packet-giop.c b/epan/dissectors/packet-giop.c index 2f211a7d90..0226f97249 100644 --- a/epan/dissectors/packet-giop.c +++ b/epan/dissectors/packet-giop.c @@ -1337,12 +1337,12 @@ void register_giop_user_module(giop_sub_dissector_t *sub, const gchar *name, con ws_debug_printf("giop:register_module: Module sub dissector name is %s \n", name); #endif - new_module_key = (struct giop_module_key *)wmem_alloc(wmem_epan_scope(), sizeof(struct giop_module_key)); + new_module_key = wmem_new(wmem_epan_scope(), struct giop_module_key); new_module_key->module = module; /* save Module or interface name from IDL */ - module_val = (struct giop_module_val *)wmem_alloc(wmem_epan_scope(), sizeof(struct giop_module_val)); + module_val = wmem_new(wmem_epan_scope(), struct giop_module_val); - module_val->subh = (giop_sub_handle_t *)wmem_alloc(wmem_epan_scope(), sizeof (giop_sub_handle_t)); /* init subh */ + module_val->subh = wmem_new(wmem_epan_scope(), giop_sub_handle_t); /* init subh */ module_val->subh->sub_name = name; /* save dissector name */ module_val->subh->sub_fn = sub; /* save subdissector*/ @@ -1615,7 +1615,7 @@ void register_giop_user(giop_sub_dissector_t *sub, const gchar *name, int sub_pr giop_sub_handle_t *subh; - subh = (giop_sub_handle_t *)wmem_alloc(wmem_epan_scope(), sizeof (giop_sub_handle_t)); + subh = wmem_new(wmem_epan_scope(), giop_sub_handle_t); subh->sub_name = name; subh->sub_fn = sub; diff --git a/epan/dissectors/packet-hpfeeds.c b/epan/dissectors/packet-hpfeeds.c index 66ff034dbb..a5abc14f56 100644 --- a/epan/dissectors/packet-hpfeeds.c +++ b/epan/dissectors/packet-hpfeeds.c @@ -230,7 +230,7 @@ static tap_packet_status hpfeeds_stats_tree_packet(stats_tree* st _U_, packet_in } if (cur == NULL) { - ch_node = (struct channel_node*)wmem_alloc0(wmem_file_scope(), sizeof(struct channel_node)); + ch_node = wmem_new0(wmem_file_scope(), struct channel_node); ch_node->channel = wmem_strdup(wmem_file_scope(), pi->channel); ch_node->st_node_channel_payload = stats_tree_create_node(st, ch_node->channel, st_node_channels_payload, STAT_DT_INT, FALSE); diff --git a/epan/dissectors/packet-idn.c b/epan/dissectors/packet-idn.c index 0458f8d595..6330a6ded1 100644 --- a/epan/dissectors/packet-idn.c +++ b/epan/dissectors/packet-idn.c @@ -937,7 +937,7 @@ static int dissect_idn_message_header(tvbuff_t *tvb, int offset, proto_tree *idn static int dissect_idn_message(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *idn_tree) { int scm; configuration_info *config = NULL; - message_info *minfo = (message_info *)wmem_alloc(wmem_file_scope(), sizeof(message_info)); + message_info *minfo = wmem_new(wmem_file_scope(), message_info); offset = dissect_idn_message_header(tvb, offset, idn_tree, minfo); determine_message_type(pinfo, minfo); @@ -945,7 +945,7 @@ static int dissect_idn_message(tvbuff_t *tvb, packet_info *pinfo, int offset, pr return offset; if(minfo->has_config_header && minfo->chunk_type != IDNCT_LP_FRAME_SF) { - config = (configuration_info *)wmem_alloc0(wmem_file_scope(), sizeof(configuration_info)); + config = wmem_new0(wmem_file_scope(), configuration_info); offset = dissect_idn_channel_configuration(tvb, pinfo, offset, idn_tree, minfo, config); }else if(minfo->chunk_type != IDNCT_VOID) { config = get_configuration_info(pinfo, minfo->channel_id); diff --git a/epan/dissectors/packet-ieee802a.c b/epan/dissectors/packet-ieee802a.c index 4e68ddcca6..0d78073051 100644 --- a/epan/dissectors/packet-ieee802a.c +++ b/epan/dissectors/packet-ieee802a.c @@ -46,7 +46,7 @@ ieee802a_add_oui(guint32 oui, const char *table_name, const char *table_ui_name, { oui_info_t *new_info; - new_info = (oui_info_t *)g_malloc(sizeof (oui_info_t)); + new_info = g_new(oui_info_t, 1); new_info->table = register_dissector_table(table_name, table_ui_name, proto, FT_UINT16, BASE_HEX); new_info->field_info = hf_item; diff --git a/epan/dissectors/packet-imf.c b/epan/dissectors/packet-imf.c index 18c1352d04..1ad5c83d70 100644 --- a/epan/dissectors/packet-imf.c +++ b/epan/dissectors/packet-imf.c @@ -973,11 +973,11 @@ header_fields_post_update_cb (void) if (num_header_fields) { custom_field_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_imf_field); - dynamic_hf = (hf_register_info *)g_malloc0 (sizeof (hf_register_info) * num_header_fields); + dynamic_hf = g_new0(hf_register_info, num_header_fields); dynamic_hf_size = num_header_fields; for (guint i = 0; i < dynamic_hf_size; i++) { - hf_id = (gint *)g_malloc (sizeof (gint)); + hf_id = g_new(gint, 1); *hf_id = -1; header_name = g_strdup (header_fields[i].header_name); @@ -991,7 +991,7 @@ header_fields_post_update_cb (void) dynamic_hf[i].hfinfo.blurb = g_strdup (header_fields[i].description); HFILL_INIT(dynamic_hf[i]); - imffield = (struct imf_field *)g_malloc (sizeof (struct imf_field)); + imffield = g_new(struct imf_field, 1); imffield->hf_id = hf_id; imffield->name = g_ascii_strdown(header_name, -1); switch (header_fields[i].header_format) { diff --git a/epan/dissectors/packet-infiniband.c b/epan/dissectors/packet-infiniband.c index d2d8809703..ad58ed6235 100644 --- a/epan/dissectors/packet-infiniband.c +++ b/epan/dissectors/packet-infiniband.c @@ -3325,10 +3325,10 @@ static void save_conversation_info(packet_info *pinfo, guint8 *local_gid, guint8 connection_context *connection; conversation_infiniband_data *proto_data; conversation_t *conv; - guint64 *hash_key = (guint64 *)g_malloc(sizeof(guint64)); + guint64 *hash_key = g_new(guint64, 1); /* create a new connection context and store it in the hash table */ - connection = (connection_context *)g_malloc(sizeof(connection_context)); + connection = g_new(connection_context, 1); if (pinfo->dst.type == AT_IPv4) { memcpy(&(connection->req_gid), local_gid, 4); diff --git a/epan/dissectors/packet-ipmi.c b/epan/dissectors/packet-ipmi.c index 7fc4e13058..91ab7655b8 100644 --- a/epan/dissectors/packet-ipmi.c +++ b/epan/dissectors/packet-ipmi.c @@ -1122,7 +1122,7 @@ ipmi_register_netfn_cmdtab(guint32 netfn, guint oem_selector, return; } - inh = (struct ipmi_netfn_handler *)wmem_alloc(wmem_epan_scope(), sizeof(struct ipmi_netfn_handler)); + inh = wmem_new(wmem_epan_scope(), struct ipmi_netfn_handler); inh->desc = desc; inh->oem_selector = oem_selector; inh->sig = sig; diff --git a/epan/dissectors/packet-ipsec.c b/epan/dissectors/packet-ipsec.c index 2b736ddcad..63acc3c1f6 100644 --- a/epan/dissectors/packet-ipsec.c +++ b/epan/dissectors/packet-ipsec.c @@ -404,7 +404,7 @@ void esp_sa_record_add_from_dissector(guint8 protocol, const gchar *srcIP, const { uat_esp_sa_record_t* record = NULL; if (extra_esp_sa_records.num_records == 0) { - extra_esp_sa_records.records = (uat_esp_sa_record_t *)g_malloc(sizeof(uat_esp_sa_record_t)*MAX_EXTRA_SA_RECORDS); + extra_esp_sa_records.records = g_new(uat_esp_sa_record_t, MAX_EXTRA_SA_RECORDS); } if (extra_esp_sa_records.num_records < MAX_EXTRA_SA_RECORDS) { record = &extra_esp_sa_records.records[extra_esp_sa_records.num_records++]; diff --git a/epan/dissectors/packet-k12.c b/epan/dissectors/packet-k12.c index cf43175b40..dd08af5423 100644 --- a/epan/dissectors/packet-k12.c +++ b/epan/dissectors/packet-k12.c @@ -301,7 +301,7 @@ k12_update_cb(void* r, char** err) g_free(h->handles); /* Allocate extra space for NULL marker */ - h->handles = (dissector_handle_t *)g_malloc0(sizeof(dissector_handle_t)*(num_protos+1)); + h->handles = g_new0(dissector_handle_t, (num_protos+1)); for (i = 0; i < num_protos; i++) { if ( ! (h->handles[i] = find_dissector(protos[i])) ) { diff --git a/epan/dissectors/packet-mac-lte-framed.c b/epan/dissectors/packet-mac-lte-framed.c index b901add561..0a805513af 100644 --- a/epan/dissectors/packet-mac-lte-framed.c +++ b/epan/dissectors/packet-mac-lte-framed.c @@ -51,7 +51,7 @@ static int dissect_mac_lte_framed(tvbuff_t *tvb, packet_info *pinfo, p_mac_lte_info = (struct mac_lte_info*)p_get_proto_data(wmem_file_scope(), pinfo, proto_mac_lte, 0); if (p_mac_lte_info == NULL) { /* Allocate new info struct for this frame */ - p_mac_lte_info = (struct mac_lte_info*)wmem_alloc0(wmem_file_scope(), sizeof(struct mac_lte_info)); + p_mac_lte_info = wmem_new0(wmem_file_scope(), struct mac_lte_info); infoAlreadySet = FALSE; } else { diff --git a/epan/dissectors/packet-mswsp.c b/epan/dissectors/packet-mswsp.c index 09d412bf06..37ad06c2b2 100644 --- a/epan/dissectors/packet-mswsp.c +++ b/epan/dissectors/packet-mswsp.c @@ -755,7 +755,7 @@ static struct message_data *find_or_create_message_data(struct mswsp_ct *conv_da result = g_slist_find_custom(conv_data->GSL_message_data, &to_find, (GCompareFunc)msg_data_find); if (!result) { - msg_data = (struct message_data *)wmem_alloc(wmem_file_scope(), sizeof(struct message_data)); + msg_data = wmem_new(wmem_file_scope(), struct message_data); *msg_data = to_find; conv_data->GSL_message_data = g_slist_prepend(conv_data->GSL_message_data, msg_data); } else { diff --git a/epan/dissectors/packet-mtp3.c b/epan/dissectors/packet-mtp3.c index 559e95a8eb..a04b017047 100644 --- a/epan/dissectors/packet-mtp3.c +++ b/epan/dissectors/packet-mtp3.c @@ -781,8 +781,8 @@ dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ /* create display subtree for the protocol */ mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3); - mtp3_addr_opc = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t)); - mtp3_addr_dpc = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t)); + mtp3_addr_opc = wmem_new0(pinfo->pool, mtp3_addr_pc_t); + mtp3_addr_dpc = wmem_new0(pinfo->pool, mtp3_addr_pc_t); /* Dissect the packet (even if !tree so can call sub-dissectors and update * the source and destination address columns) */ diff --git a/epan/dissectors/packet-nano.c b/epan/dissectors/packet-nano.c index b0cbbacd66..fe687835f9 100644 --- a/epan/dissectors/packet-nano.c +++ b/epan/dissectors/packet-nano.c @@ -743,7 +743,7 @@ static int dissect_nano_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, session_state = (struct nano_session_state *)conversation_get_proto_data(conversation, proto_nano); if (!session_state) { // create new session state - session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state)); + session_state = wmem_new0(wmem_file_scope(), struct nano_session_state); session_state->client_packet_type = NANO_PACKET_TYPE_INVALID; session_state->server_port = pinfo->match_uint; conversation_add_proto_data(conversation, proto_nano, session_state); @@ -753,7 +753,7 @@ static int dissect_nano_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, packet_session_state = (struct nano_session_state *)p_get_proto_data(wmem_file_scope(), pinfo, proto_nano, 0); if (!packet_session_state) { // this packet does not have a stored session state, get it from the conversation - packet_session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state)); + packet_session_state = wmem_new0(wmem_file_scope(), struct nano_session_state); memcpy(packet_session_state, session_state, sizeof(struct nano_session_state)); p_add_proto_data(wmem_file_scope(), pinfo, proto_nano, 0, packet_session_state); } else { @@ -827,7 +827,7 @@ static gboolean dissect_nano_heur_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_t session_state = (struct nano_session_state *)conversation_get_proto_data(conversation, proto_nano); if (!session_state) { // create new session state - session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state)); + session_state = wmem_new0(wmem_file_scope(), struct nano_session_state); session_state->client_packet_type = NANO_PACKET_TYPE_INVALID; session_state->server_port = pinfo->destport; conversation_add_proto_data(conversation, proto_nano, session_state); diff --git a/epan/dissectors/packet-nvme-tcp.c b/epan/dissectors/packet-nvme-tcp.c index 8bd868bd65..40180eb9c5 100644 --- a/epan/dissectors/packet-nvme-tcp.c +++ b/epan/dissectors/packet-nvme-tcp.c @@ -1118,8 +1118,7 @@ dissect_nvme_tcp_pdu(tvbuff_t *tvb, conversation_get_proto_data(conversation, proto_nvme_tcp); if (!q_ctx) { - q_ctx = (struct nvme_tcp_q_ctx *) wmem_alloc0(wmem_file_scope(), - sizeof(struct nvme_tcp_q_ctx)); + q_ctx = wmem_new0(wmem_file_scope(), struct nvme_tcp_q_ctx); q_ctx->n_q_ctx.pending_cmds = wmem_tree_new(wmem_file_scope()); q_ctx->n_q_ctx.done_cmds = wmem_tree_new(wmem_file_scope()); q_ctx->n_q_ctx.data_requests = wmem_tree_new(wmem_file_scope()); diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c index b745619407..6a88193582 100644 --- a/epan/dissectors/packet-radius.c +++ b/epan/dissectors/packet-radius.c @@ -1677,7 +1677,7 @@ dissect_attribute_value_pairs(proto_tree *tree, packet_info *pinfo, tvbuff_t *tv if (avp_vsa_flags & 0x80) { if (!vsa_buffer) { - vsa_buffer = (radius_vsa_buffer *)g_malloc(sizeof(radius_vsa_buffer)); + vsa_buffer = g_new(radius_vsa_buffer, 1); vsa_buffer->key.vendor_id = vendor_id; vsa_buffer->key.vsa_type = avp_vsa_type; vsa_buffer->len = avp_vsa_len; @@ -2482,7 +2482,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a vendor = (radius_vendor_info_t *)g_hash_table_lookup(dict->vendors_by_id, GUINT_TO_POINTER(vendor_id)); if (!vendor) { - vendor = (radius_vendor_info_t *)g_malloc(sizeof(radius_vendor_info_t)); + vendor = g_new(radius_vendor_info_t, 1); vendor->name = g_strdup_printf("%s-%u", enterprises_lookup(vendor_id, "Unknown"), @@ -2508,7 +2508,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a } if (!dictionary_entry) { - dictionary_entry = (radius_attr_info_t *)g_malloc(sizeof(radius_attr_info_t)); + dictionary_entry = g_new(radius_attr_info_t, 1); dictionary_entry->name = g_strdup_printf("Unknown-Attribute-%u", attribute_id.value); dictionary_entry->code = attribute_id; @@ -2849,7 +2849,7 @@ proto_register_radius(void) radius_tap = register_tap("radius"); proto_register_prefix("radius", register_radius_fields); - dict = (radius_dictionary_t *)g_malloc(sizeof(radius_dictionary_t)); + dict = g_new(radius_dictionary_t, 1); /* * IDs map to names and vice versa. The attribute and vendor is stored * only once, but referenced by both name and ID mappings. diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c index 79ec7bd033..5a9a22544e 100644 --- a/epan/dissectors/packet-rpc.c +++ b/epan/dissectors/packet-rpc.c @@ -521,7 +521,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers, size_t versidx; const vsff *proc; - value = (rpc_prog_info_value *) g_malloc(sizeof(rpc_prog_info_value)); + value = g_new(rpc_prog_info_value, 1); value->proto = find_protocol_by_id(proto); value->proto_id = proto; value->ett = ett; diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index 92b80ad836..a9c0cc9abc 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -2762,7 +2762,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn, msg = find_message(stream_id, stream_seq_num, u_bit); if (!msg) { - msg = (sctp_frag_msg *)g_malloc (sizeof (sctp_frag_msg)); + msg = g_new(sctp_frag_msg, 1); msg->begins = NULL; msg->ends = NULL; msg->fragments = NULL; @@ -2776,7 +2776,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn, else msg->ppi = ppi; - key = (frag_key *)g_malloc(sizeof (frag_key)); + key = g_new(frag_key, 1); key->sport = sctp_info.sport; key->dport = sctp_info.dport; key->verification_tag = sctp_info.verification_tag; @@ -2820,7 +2820,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn, return NULL; /* create new fragment */ - fragment = (sctp_fragment *)g_malloc (sizeof (sctp_fragment)); + fragment = g_new(sctp_fragment, 1); fragment->frame_num = pinfo->num; fragment->tsn = tsn; fragment->len = tvb_captured_length(tvb); @@ -2850,7 +2850,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn, /* save begin or end if necessary */ if (b_bit && !e_bit) { - beginend = (sctp_frag_be *)g_malloc (sizeof (sctp_frag_be)); + beginend = g_new(sctp_frag_be, 1); beginend->fragment = fragment; beginend->next = NULL; @@ -2875,7 +2875,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn, } if (!b_bit && e_bit) { - beginend = (sctp_frag_be *)g_malloc (sizeof (sctp_frag_be)); + beginend = g_new(sctp_frag_be, 1); beginend->fragment = fragment; beginend->next = NULL; diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c index 39fe67a400..66f0349ac6 100644 --- a/epan/dissectors/packet-smb.c +++ b/epan/dissectors/packet-smb.c @@ -1286,7 +1286,7 @@ smb_eo_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const entry = g_new(export_object_entry_t, 1); entry->payload_data = NULL; entry->payload_len = 0; - new_file = (active_file *)g_malloc(sizeof(active_file)); + new_file = g_new(active_file, 1); new_file->tid = incoming_file.tid; new_file->uid = incoming_file.uid; new_file->fid = incoming_file.fid; @@ -18010,7 +18010,7 @@ dissect_smb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* da si->ct = (conv_tables_t *)conversation_get_proto_data(conversation, proto_smb); if (!si->ct) { /* No, not yet. create it and attach it to the conversation */ - si->ct = (conv_tables_t *)g_malloc(sizeof(conv_tables_t)); + si->ct = g_new(conv_tables_t, 1); conv_tables = g_slist_prepend(conv_tables, si->ct); si->ct->matched = g_hash_table_new(smb_saved_info_hash_matched, diff --git a/epan/dissectors/packet-smtp.c b/epan/dissectors/packet-smtp.c index 096b6780cf..f83cca3689 100644 --- a/epan/dissectors/packet-smtp.c +++ b/epan/dissectors/packet-smtp.c @@ -429,7 +429,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ /* * No - create one and attach it. */ - session_state = (struct smtp_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct smtp_session_state)); + session_state = wmem_new0(wmem_file_scope(), struct smtp_session_state); session_state->smtp_state = SMTP_STATE_START; session_state->auth_state = SMTP_AUTH_STATE_NONE; session_state->msg_last = TRUE; @@ -455,7 +455,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ /* * Create a frame data structure and attach it to the packet. */ - spd_frame_data = (struct smtp_proto_data *)wmem_alloc0(wmem_file_scope(), sizeof(struct smtp_proto_data)); + spd_frame_data = wmem_new0(wmem_file_scope(), struct smtp_proto_data); spd_frame_data->conversation_id = conversation->conv_index; spd_frame_data->more_frags = TRUE; diff --git a/epan/dissectors/packet-snort-config.c b/epan/dissectors/packet-snort-config.c index 1bf3f42d9a..0ced5c7407 100644 --- a/epan/dissectors/packet-snort-config.c +++ b/epan/dissectors/packet-snort-config.c @@ -741,7 +741,7 @@ static gboolean parse_rule(SnortConfig_t *snort_config, char *line, const char * } /* Allocate the rule itself */ - rule = (Rule_t*)g_malloc(sizeof(Rule_t)); + rule = g_new(Rule_t, 1); snort_debug_printf("looks like a rule: %s\n", line); memset(rule, 0, sizeof(Rule_t)); @@ -905,7 +905,7 @@ void create_config(SnortConfig_t **snort_config, const char *snort_config_file) snort_debug_printf("create_config (%s)\n", snort_config_file); - *snort_config = (SnortConfig_t*)g_malloc(sizeof(SnortConfig_t)); + *snort_config = g_new(SnortConfig_t, 1); memset(*snort_config, 0, sizeof(SnortConfig_t)); /* Create rule table */ diff --git a/epan/dissectors/packet-snort.c b/epan/dissectors/packet-snort.c index 2add440baf..5d9f1efe71 100644 --- a/epan/dissectors/packet-snort.c +++ b/epan/dissectors/packet-snort.c @@ -211,7 +211,7 @@ static void add_alert_to_session_tree(guint frame_number, Alert_t *alert) Alerts_t *alerts = (Alerts_t*)wmem_tree_lookup32(current_session.alerts_tree, frame_number); if (alerts == NULL) { /* Create a new entry for the table */ - alerts = (Alerts_t*)g_malloc(sizeof(Alerts_t)); + alerts = g_new(Alerts_t, 1); /* Deep copy of alert */ alerts->alerts[0] = *alert; alerts->num_alerts = 1; diff --git a/epan/dissectors/packet-soupbintcp.c b/epan/dissectors/packet-soupbintcp.c index 8a89ae0ba5..50eb41026a 100644 --- a/epan/dissectors/packet-soupbintcp.c +++ b/epan/dissectors/packet-soupbintcp.c @@ -205,7 +205,7 @@ dissect_soupbintcp_common( 0); /* Store starting sequence number for session's packets */ - conv_data = (struct conv_data *)wmem_alloc(wmem_file_scope(), sizeof(struct conv_data)); + conv_data = wmem_new(wmem_file_scope(), struct conv_data); conv_data->next_seq = next_seq; conversation_add_proto_data(conv, proto_soupbintcp, conv_data); } @@ -226,9 +226,7 @@ dissect_soupbintcp_common( this_seq = 0; } - pdu_data = (struct pdu_data *)wmem_alloc( - wmem_file_scope(), - sizeof(struct pdu_data)); + pdu_data = wmem_new(wmem_file_scope(), struct pdu_data); pdu_data->seq_num = this_seq; p_add_proto_data(wmem_file_scope(), pinfo, proto_soupbintcp, key, pdu_data); } diff --git a/epan/dissectors/packet-ssh.c b/epan/dissectors/packet-ssh.c index 6b05061991..e909b437d2 100644 --- a/epan/dissectors/packet-ssh.c +++ b/epan/dissectors/packet-ssh.c @@ -458,7 +458,7 @@ dissect_ssh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) global_data = (struct ssh_flow_data *)conversation_get_proto_data(conversation, proto_ssh); if (!global_data) { - global_data = (struct ssh_flow_data *)wmem_alloc0(wmem_file_scope(), sizeof(struct ssh_flow_data)); + global_data = wmem_new0(wmem_file_scope(), struct ssh_flow_data); global_data->version = SSH_VERSION_UNKNOWN; global_data->kex_specific_dissector = ssh_dissect_kex_dh; global_data->peer_data[CLIENT_PEER_DATA].mac_length = -1; diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c index 9b83e8d84c..3209042b40 100644 --- a/epan/dissectors/packet-tpncp.c +++ b/epan/dissectors/packet-tpncp.c @@ -801,8 +801,7 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file) field = &data_fields_info[data_id]; current_data_id = data_id; } else { - field->p_next = (tpncp_data_field_info *) wmem_alloc( - wmem_epan_scope(), sizeof (tpncp_data_field_info)); + field->p_next = wmem_new(wmem_epan_scope(), tpncp_data_field_info); if (!field->p_next) return (-1); field = field->p_next; diff --git a/epan/dissectors/packet-twamp.c b/epan/dissectors/packet-twamp.c index cd135fa61c..c2f13c269f 100644 --- a/epan/dissectors/packet-twamp.c +++ b/epan/dissectors/packet-twamp.c @@ -251,7 +251,7 @@ dissect_twamp_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void /* try to find session from past visits */ if ((list = g_slist_find_custom(ct->sessions, &sender_port, (GCompareFunc) find_twamp_session_by_sender_port)) == NULL) { - session = (twamp_session_t *) g_malloc0(sizeof(twamp_session_t)); + session = g_new0(twamp_session_t, 1); session->sender_port = sender_port; session->receiver_port = receiver_port; session->accepted = 0; diff --git a/epan/dissectors/packet-umts_rlc.c b/epan/dissectors/packet-umts_rlc.c index 222a88eacb..e453c77ac3 100644 --- a/epan/dissectors/packet-umts_rlc.c +++ b/epan/dissectors/packet-umts_rlc.c @@ -378,7 +378,7 @@ rlc_channel_create(enum rlc_mode mode, packet_info *pinfo, struct atm_phdr *atm) struct rlc_channel *ch; int rv; - ch = (struct rlc_channel *)g_malloc0(sizeof(struct rlc_channel)); + ch = g_new0(struct rlc_channel, 1); rv = rlc_channel_assign(ch, mode, pinfo, atm); if (rv != 0) { @@ -423,7 +423,7 @@ rlc_sdu_create(void) { struct rlc_sdu *sdu; - sdu = (struct rlc_sdu *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_sdu)); + sdu = wmem_new0(wmem_file_scope(), struct rlc_sdu); return sdu; } @@ -484,7 +484,7 @@ rlc_frag_create(tvbuff_t *tvb, enum rlc_mode mode, packet_info *pinfo, { struct rlc_frag *frag; - frag = (struct rlc_frag *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_frag)); + frag = wmem_new0(wmem_file_scope(), struct rlc_frag); rlc_frag_assign(frag, mode, pinfo, seq, li, atm); rlc_frag_assign_data(frag, tvb, offset, length); @@ -1302,7 +1302,7 @@ rlc_is_duplicate(enum rlc_mode mode, packet_info *pinfo, guint16 seq, } if(is_unseen) { /* Add to list for the first time this frame is checked */ - seq_new = (struct rlc_seq *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_seq)); + seq_new = wmem_new0(wmem_file_scope(), struct rlc_seq); *seq_new = seq_item; seq_new->arrival = pinfo->abs_ts; list->list = g_list_append(list->list, seq_new); /* insert in order of arrival */ @@ -1603,7 +1603,7 @@ rlc_decipher(tvbuff_t *tvb, packet_info * pinfo, proto_tree * tree, fp_info * fp if(!tree){ /*Preserve counter value for next dissection round*/ guint32 * ciph; - ciph = (guint32 *)g_malloc(sizeof(guint32)*2); + ciph = g_new(guint32, 2); ciph[0] = ps_counter[rlcinf->rbid[pos]][0]; ciph[1] = ps_counter[rlcinf->rbid[pos]][1]; g_tree_insert(counter_map, GINT_TO_POINTER((gint)pinfo->num), ciph); @@ -1643,7 +1643,7 @@ rlc_decipher(tvbuff_t *tvb, packet_info * pinfo, proto_tree * tree, fp_info * fp if(!tree){/*Preserve counter for second packet analysis run*/ guint32 * ciph; - ciph = (guint32 *)g_malloc(sizeof(guint32)*2); + ciph = g_new(guint32, 2); ciph[0] = ps_counter[rlcinf->rbid[pos]][0]; ciph[1] = ps_counter[rlcinf->rbid[pos]][1]; g_tree_insert(counter_map, GINT_TO_POINTER((gint)pinfo->num+1), ciph); diff --git a/epan/dissectors/packet-zvt.c b/epan/dissectors/packet-zvt.c index e7f714a67c..80e8078027 100644 --- a/epan/dissectors/packet-zvt.c +++ b/epan/dissectors/packet-zvt.c @@ -477,8 +477,7 @@ dissect_zvt_tlv_seq(tvbuff_t *tvb, gint offset, guint16 seq_max_len, gint ret; if (!seq_info) { - seq_info = (tlv_seq_info_t *)wmem_alloc( - wmem_packet_scope(), sizeof(tlv_seq_info_t)); + seq_info = wmem_new(wmem_packet_scope(), tlv_seq_info_t); /* by default, text lines are using the CP437 charset there's an object to change the encoding |