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.
This commit is contained in:
Moshe Kaplan 2020-12-20 21:30:28 -05:00 committed by AndersBroman
parent 7b27b444cb
commit e16166a74c
124 changed files with 437 additions and 327 deletions

View File

@ -40,12 +40,12 @@ static GList * append_remote_list(GList *iflist)
for (rlist = g_list_nth(remote_interface_list, 0); rlist != NULL; rlist = g_list_next(rlist)) {
if_info = (if_info_t *)rlist->data;
temp = (if_info_t*) g_malloc0(sizeof(if_info_t));
temp = g_new0(if_info_t, 1);
temp->name = g_strdup(if_info->name);
temp->friendly_name = g_strdup(if_info->friendly_name);
temp->vendor_description = g_strdup(if_info->vendor_description);
for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) {
temp_addr = (if_addr_t *) g_malloc0(sizeof(if_addr_t));
temp_addr = g_new0(if_addr_t, 1);
if_addr = (if_addr_t *)list->data;
if (if_addr) {
temp_addr->ifat_type = if_addr->ifat_type;
@ -342,12 +342,12 @@ void add_interface_to_remote_list(if_info_t *if_info)
GSList *list;
if_addr_t *if_addr, *temp_addr;
if_info_t *temp = (if_info_t*) g_malloc0(sizeof(if_info_t));
if_info_t *temp = g_new0(if_info_t, 1);
temp->name = g_strdup(if_info->name);
temp->friendly_name = g_strdup(if_info->friendly_name);
temp->vendor_description = g_strdup(if_info->vendor_description);
for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) {
temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t));
temp_addr = g_new0(if_addr_t, 1);
if_addr = (if_addr_t *)list->data;
if (if_addr) {
temp_addr->ifat_type = if_addr->ifat_type;

View File

@ -537,7 +537,7 @@ airpcap_if_info_new(char *name, char *description)
ad = airpcap_if_open(name, ebuf);
if (ad)
{
if_info = (airpcap_if_info_t *)g_malloc0(sizeof (airpcap_if_info_t));
if_info = g_new0(airpcap_if_info_t, 1);
if_info->name = g_strdup(name);
if (description == NULL){
if_info->description = NULL;
@ -595,7 +595,7 @@ airpcap_driver_fake_if_info_new(void)
ad = airpcap_if_open(if_info->name, ebuf);
if (ad)
{
fake_if_info = (airpcap_if_info_t *)g_malloc0(sizeof (airpcap_if_info_t));
fake_if_info = g_new0(airpcap_if_info_t, 1);
fake_if_info->name = g_strdup(if_info->name);
fake_if_info->description = g_strdup(if_info->description);
fake_if_info->loopback = FALSE;
@ -946,7 +946,7 @@ airpcap_get_if_string_number_from_description(gchar* description)
gchar* number;
gchar* pointer;
number = (gchar*)g_malloc(sizeof(gchar)*3);
number = g_new(gchar, 3);
pointer = g_strrstr(description,"#\0");

View File

@ -419,7 +419,7 @@ if_info_new(const char *name, const char *description, gboolean loopback)
GUID guid;
#endif
if_info = (if_info_t *)g_malloc(sizeof (if_info_t));
if_info = g_new(if_info_t, 1);
if_info->name = g_strdup(name);
if_info->friendly_name = NULL; /* default - unknown */
if_info->vendor_description = NULL;
@ -909,7 +909,7 @@ create_data_link_info(int dlt)
data_link_info_t *data_link_info;
const char *text;
data_link_info = (data_link_info_t *)g_malloc(sizeof (data_link_info_t));
data_link_info = g_new(data_link_info_t, 1);
data_link_info->dlt = dlt;
text = pcap_datalink_val_to_name(dlt);
if (text != NULL)

View File

@ -912,7 +912,7 @@ print_statistics_loop(gboolean machine_readable)
#endif
if (pch) {
if_stat = (if_stat_t *)g_malloc(sizeof(if_stat_t));
if_stat = g_new(if_stat_t, 1);
if_stat->name = g_strdup(if_info->name);
if_stat->pch = pch;
stat_list = g_list_append(stat_list, if_stat);
@ -2760,7 +2760,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
int pcapng_src_count = 0;
for (i = 0; i < capture_opts->ifaces->len; i++) {
interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
pcap_src = (capture_src *)g_malloc0(sizeof (capture_src));
pcap_src = g_new0(capture_src, 1);
if (pcap_src == NULL) {
g_snprintf(errmsg, (gulong) errmsg_len,
"Could not allocate memory.");
@ -4509,7 +4509,7 @@ capture_loop_queue_packet_cb(u_char *pcap_src_p, const struct pcap_pkthdr *phdr,
return;
}
queue_element = (pcap_queue_element *)g_malloc(sizeof(pcap_queue_element));
queue_element = g_new(pcap_queue_element, 1);
if (queue_element == NULL) {
pcap_src->dropped++;
return;
@ -4569,7 +4569,7 @@ capture_loop_queue_pcapng_cb(capture_src *pcap_src, const pcapng_block_header_t
return;
}
queue_element = (pcap_queue_element *)g_malloc(sizeof(pcap_queue_element));
queue_element = g_new(pcap_queue_element, 1);
if (queue_element == NULL) {
pcap_src->dropped++;
return;

View File

@ -910,7 +910,7 @@ list_encap_types(FILE *stream) {
struct string_elem *encaps;
GSList *list = NULL;
encaps = (struct string_elem *)g_malloc(sizeof(struct string_elem) * WTAP_NUM_ENCAP_TYPES);
encaps = g_new(struct string_elem, WTAP_NUM_ENCAP_TYPES);
fprintf(stream, "editcap: The available encapsulation types for the \"-T\" flag are:\n");
for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
encaps[i].sstr = wtap_encap_name(i);

View File

@ -61,7 +61,7 @@ color_filter_new(const gchar *name, /* The name of the filter to create
{
color_filter_t *colorf;
colorf = (color_filter_t *)g_malloc0(sizeof (color_filter_t));
colorf = g_new0(color_filter_t, 1);
colorf->filter_name = g_strdup(name);
colorf->filter_text = g_strdup(filter_string);
colorf->bg_color = *bg_color;
@ -261,7 +261,7 @@ color_filter_clone(color_filter_t *colorf)
{
color_filter_t *new_colorf;
new_colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t));
new_colorf = g_new(color_filter_t, 1);
new_colorf->filter_name = g_strdup(colorf->filter_name);
new_colorf->filter_text = g_strdup(colorf->filter_text);
new_colorf->bg_color = colorf->bg_color;

View File

@ -846,17 +846,17 @@ col_finalize(column_info *cinfo)
col_item->col_custom_dfilter = NULL;
}
col_item->fmt_matx = (gboolean *) g_malloc0(sizeof(gboolean) * NUM_COL_FMTS);
col_item->fmt_matx = g_new0(gboolean, NUM_COL_FMTS);
get_column_format_matches(col_item->fmt_matx, col_item->col_fmt);
col_item->col_data = NULL;
if (col_item->col_fmt == COL_INFO)
col_item->col_buf = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
col_item->col_buf = g_new(gchar, COL_MAX_INFO_LEN);
else
col_item->col_buf = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
col_item->col_buf = g_new(gchar, COL_MAX_LEN);
cinfo->col_expr.col_expr[i] = "";
cinfo->col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
cinfo->col_expr.col_expr_val[i] = g_new(gchar, COL_MAX_LEN);
}
cinfo->col_expr.col_expr[i] = NULL;

View File

@ -24,7 +24,7 @@ void register_conversation_filter(const char *proto_name, const char *display_na
is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string) {
conversation_filter_t *entry;
entry = (conversation_filter_t *)g_malloc(sizeof(conversation_filter_t));
entry = g_new(conversation_filter_t, 1);
entry->proto_name = proto_name;
entry->display_name = display_name;

View File

@ -2487,7 +2487,7 @@ parse_key_string(gchar* input_string, guint8 key_type)
if (res && key_ba->len > 0) {
/* Key is correct! It was probably an 'old style' WEP key */
/* Create the decryption_key_t structure, fill it and return it*/
dk = (decryption_key_t *)g_malloc(sizeof(decryption_key_t));
dk = g_new(decryption_key_t, 1);
dk->type = DOT11DECRYPT_KEY_TYPE_WEP;
/* XXX - The current key handling code in the GUI requires
@ -2579,7 +2579,7 @@ parse_key_string(gchar* input_string, guint8 key_type)
}
/* Key was correct!!! Create the new decryption_key_t ... */
dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
dk = g_new(decryption_key_t, 1);
dk->type = DOT11DECRYPT_KEY_TYPE_WPA_PWD;
dk->key = g_string_new(key);
@ -2613,7 +2613,7 @@ parse_key_string(gchar* input_string, guint8 key_type)
}
/* Key was correct!!! Create the new decryption_key_t ... */
dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
dk = g_new(decryption_key_t, 1);
dk->type = DOT11DECRYPT_KEY_TYPE_WPA_PSK;
dk->key = g_string_new(input_string);
@ -2647,7 +2647,7 @@ parse_key_string(gchar* input_string, guint8 key_type)
g_byte_array_free(key_ba, TRUE);
return NULL;
}
dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
dk = g_new(decryption_key_t, 1);
dk->type = DOT11DECRYPT_KEY_TYPE_TK;
dk->key = g_string_new(input_string);
dk->bits = (guint) dk->key->len * 4;

View File

@ -355,7 +355,7 @@ read_protos_list_file(const char *ff_path, FILE *ff, GList **flp)
prot_name[prot_name_index] = '\0';
/* Add the new protocol to the list of disabled protocols */
prot = (protocol_def *) g_malloc(sizeof(protocol_def));
prot = g_new(protocol_def, 1);
prot->name = g_strdup(prot_name);
*flp = g_list_append(*flp, prot);
}
@ -671,7 +671,7 @@ read_heur_dissector_list_file(const char *ff_path, FILE *ff, GList **flp)
heuristic_name[name_index] = '\0';
/* Add the new protocol to the list of protocols */
heur = (heur_protocol_def *) g_malloc(sizeof(heur_protocol_def));
heur = g_new(heur_protocol_def, 1);
heur->name = g_strdup(heuristic_name);
heur->enabled = enabled;
*flp = g_list_append(*flp, heur);

View File

@ -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);

View File

@ -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++;
}

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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++];

View File

@ -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])) ) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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) */

View File

@ -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);

View File

@ -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());

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -95,7 +95,7 @@ void funnel_register_menu(const char *name,
funnel_menu_callback_data_free callback_data_free,
gboolean retap)
{
funnel_menu_t* m = (funnel_menu_t *)g_malloc(sizeof(funnel_menu_t));
funnel_menu_t* m = g_new(funnel_menu_t, 1);
m->name = g_strdup(name);
m->group = group;
m->callback = callback;
@ -114,7 +114,7 @@ void funnel_register_menu(const char *name,
void funnel_deregister_menus(funnel_menu_callback callback)
{
funnel_menu_t* m = (funnel_menu_t *)g_malloc0(sizeof(funnel_menu_t));
funnel_menu_t* m = g_new0(funnel_menu_t, 1);
m->callback = callback;
funnel_remove_menu(&registered_menus, m);

View File

@ -1074,7 +1074,7 @@ dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t h
dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors);
#endif
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current;
@ -1330,7 +1330,7 @@ dissector_change_uint(const char *name, const guint32 pattern, dissector_handle_
if (handle == NULL)
return;
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->initial = NULL;
dtbl_entry->current = handle;
@ -1554,7 +1554,7 @@ dissector_add_string(const char *name, const gchar *pattern,
g_assert_not_reached();
}
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current;
@ -1638,7 +1638,7 @@ dissector_change_string(const char *name, const gchar *pattern,
if (handle == NULL)
return;
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->initial = NULL;
dtbl_entry->current = handle;
@ -1800,7 +1800,7 @@ void dissector_add_custom_table_handle(const char *name, void *pattern, dissecto
g_assert(sub_dissectors->type == FT_BYTES);
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current;
@ -1858,7 +1858,7 @@ void dissector_add_guid(const char *name, guid_key* guid_val, dissector_handle_t
g_assert_not_reached();
}
dtbl_entry = (dtbl_entry_t *)g_malloc(sizeof (dtbl_entry_t));
dtbl_entry = g_new(dtbl_entry_t, 1);
dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current;

View File

@ -72,7 +72,7 @@ extern ext_menu_t * ext_menubar_register_menu(int proto_id, const gchar * menula
/* For now, a protocol may only register one main menu */
g_assert(g_list_find(menubar_menunames, name) == NULL);
entry = (ext_menubar_t *)g_malloc0(sizeof(ext_menubar_t));
entry = g_new0(ext_menubar_t, 1);
entry->type = EXT_MENUBAR_MENU;
entry->proto = proto_id;
entry->is_plugin = is_plugin;
@ -117,7 +117,7 @@ extern ext_menu_t * ext_menubar_add_submenu(ext_menu_t * parent, const gchar *me
parent->submenu_cnt++;
/* Create submenu entry */
entry = (ext_menubar_t *)g_malloc0(sizeof(ext_menubar_t));
entry = g_new0(ext_menubar_t, 1);
entry->type = EXT_MENUBAR_MENU;
entry->parent = parent;
/* Just a convenience */
@ -147,7 +147,7 @@ static void ext_menubar_add_generic_entry (
parent->item_cnt++;
/* Create menu entry */
entry = (ext_menubar_t*)g_malloc0(sizeof(ext_menubar_t));
entry = g_new0(ext_menubar_t, 1);
entry->type = type;
/* Create unique name, which is used by GTK to provide the menu */
entry->name = g_strdup_printf("%sI%02d", parent->name, parent->item_cnt);

View File

@ -3728,7 +3728,7 @@ prefs_get_string_list(const gchar *str)
GList *sl = NULL;
/* Allocate a buffer for the first string. */
slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
slstr = g_new(gchar, COL_MAX_LEN);
j = 0;
for (;;) {
@ -3785,7 +3785,7 @@ prefs_get_string_list(const gchar *str)
slstr[j] = '\0';
if (j > 0) {
sl = g_list_append(sl, slstr);
slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
slstr = g_new(gchar, COL_MAX_LEN);
}
/* ...and the beginning of a new string. */

View File

@ -664,7 +664,7 @@ print_stream_text_alloc(gboolean to_file, FILE *fh)
output->color_type = COLOR_NONE;
}
stream = (print_stream_t *)g_malloc(sizeof (print_stream_t));
stream = g_new(print_stream_t, 1);
stream->ops = &print_text_ops;
stream->data = output;
@ -834,7 +834,7 @@ print_stream_ps_alloc(gboolean to_file, FILE *fh)
output->to_file = to_file;
output->fh = fh;
stream = (print_stream_t *)g_malloc(sizeof (print_stream_t));
stream = g_new(print_stream_t, 1);
stream->ops = &print_ps_ops;
stream->data = output;

View File

@ -72,7 +72,7 @@ p_add_proto_data(wmem_allocator_t *tmp_scope, struct _packet_info* pinfo, int pr
DISSECTOR_ASSERT(!"invalid wmem scope");
}
p1 = (proto_data_t *)wmem_alloc(scope, sizeof(proto_data_t));
p1 = wmem_new(scope, proto_data_t);
p1->proto = proto;
p1->key = key;

View File

@ -210,7 +210,7 @@ init_srt_table(const char *name, const char *short_name, GArray *srt_array, int
table->short_name = short_name;
table->proc_column_name = proc_column_name;
table->num_procs=num_procs;
table->procedures=(srt_procedure_t *)g_malloc(sizeof(srt_procedure_t)*num_procs);
table->procedures=g_new(srt_procedure_t, num_procs);
for(i=0;i<num_procs;i++){
time_stat_init(&table->procedures[i].stats);
table->procedures[i].proc_index = 0;

View File

@ -97,7 +97,7 @@ process_stat_cmd_arg(const char *optstr)
for (entry = wmem_list_tail(stat_cmd_arg_list); entry; entry = wmem_list_frame_prev(entry)) {
sca = (stat_cmd_arg*)wmem_list_frame_data(entry);
if (!strncmp(sca->cmd, stat_command, strlen(sca->cmd))) {
tr=(stat_requested *)g_malloc(sizeof (stat_requested));
tr=g_new(stat_requested, 1);
tr->sca = sca;
tr->arg = stat_command;
stats_requested = g_slist_append(stats_requested, tr);

View File

@ -176,7 +176,7 @@ reset_stat_node(stat_node *node)
node->bh = bucket->next;
g_free(bucket);
}
node->bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
node->bh = g_new0(burst_bucket, 1);
node->bt = node->bh;
node->bcount = 0;
node->max_burst = 0;
@ -231,7 +231,7 @@ stats_tree_reinit(void *p)
}
st->root.st_flags = 0;
st->root.bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
st->root.bh = g_new0(burst_bucket, 1);
st->root.bt = st->root.bh;
st->root.bcount = 0;
st->root.max_burst = 0;
@ -325,7 +325,7 @@ stats_tree_register_plugin(const char *tapname, const char *abbr, const char *na
extern stats_tree*
stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter)
{
stats_tree *st = (stats_tree *)g_malloc0(sizeof(stats_tree));
stats_tree *st = g_new0(stats_tree, 1);
st->cfg = cfg;
st->pr = pr;
@ -349,7 +349,7 @@ stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter)
break;
}
st->root.bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
st->root.bh = g_new0(burst_bucket, 1);
st->root.bt = st->root.bh;
st->root.burst_time = -1.0;
@ -462,7 +462,7 @@ new_stat_node(stats_tree *st, const gchar *name, int parent_id, stat_node_dataty
gboolean with_hash, gboolean as_parent_node)
{
stat_node *node = (stat_node *)g_malloc0(sizeof(stat_node));
stat_node *node = g_new0(stat_node, 1);
stat_node *last_chld = NULL;
node->datatype = datatype;
@ -479,7 +479,7 @@ new_stat_node(stats_tree *st, const gchar *name, int parent_id, stat_node_dataty
}
node->st_flags = parent_id?0:ST_FLG_ROOTCHILD;
node->bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
node->bh = g_new0(burst_bucket, 1);
node->bt = node->bh;
node->burst_time = -1.0;
@ -572,7 +572,7 @@ update_burst_calc(stat_node *node, gint value)
burstwin = prefs.st_burst_windowlen/prefs.st_burst_resolution;
if (current_bucket>node->bt->bucket_no) {
/* Must add a new bucket at the burst list tail */
bn = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
bn = g_new0(burst_bucket, 1);
bn->count = value;
bn->bucket_no = current_bucket;
bn->start_time = node->st->now;
@ -595,7 +595,7 @@ update_burst_calc(stat_node *node, gint value)
/* Packet must be added at head of burst list - check if not too old */
if ((current_bucket+burstwin)>node->bt->bucket_no) {
/* packet still within the window */
bn = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
bn = g_new0(burst_bucket, 1);
bn->count = value;
bn->bucket_no = current_bucket;
bn->start_time = node->st->now;
@ -622,7 +622,7 @@ update_burst_calc(stat_node *node, gint value)
}
else {
/* must add a new bucket after bn. */
bn = (burst_bucket*)g_malloc0(sizeof(burst_bucket));
bn = g_new0(burst_bucket, 1);
bn->count = value;
bn->bucket_no = current_bucket;
bn->start_time = node->st->now;
@ -805,7 +805,7 @@ get_range(char *rngstr)
return NULL;
}
rng = (range_pair_t *)g_malloc(sizeof(range_pair_t));
rng = g_new(range_pair_t, 1);
if (split[1] == NULL) {
/* means we have a non empty string with no delimiter

View File

@ -172,7 +172,7 @@ register_tap(const char *name)
tdl = tdl_prev;
}
td=(tap_dissector_t *)g_malloc(sizeof(tap_dissector_t));
td=g_new(tap_dissector_t, 1);
td->next=NULL;
td->name = g_strdup(name);
@ -527,7 +527,7 @@ register_tap_listener(const char *tapname, void *tapdata, const char *fstring,
return error_string;
}
tl=(tap_listener_t *)g_malloc0(sizeof(tap_listener_t));
tl=g_new0(tap_listener_t, 1);
tl->needs_redraw=TRUE;
tl->failed=FALSE;
tl->flags=flags;

View File

@ -843,7 +843,7 @@ static int cond_handle(tvbparse_t* tt, const int offset, const tvbparse_wanted_t
}
tvbparse_wanted_t* tvbparse_handle(tvbparse_wanted_t** handle) {
tvbparse_wanted_t* w = (tvbparse_wanted_t *)g_malloc0(sizeof(tvbparse_wanted_t));
tvbparse_wanted_t* w = g_new0(tvbparse_wanted_t, 1);
w->condition = cond_handle;
w->control.handle = handle;
@ -864,7 +864,7 @@ tvbparse_wanted_t* tvbparse_end_of_buffer(const int id,
const void* data,
tvbparse_action_t before_cb,
tvbparse_action_t after_cb) {
tvbparse_wanted_t* w = (tvbparse_wanted_t *)g_malloc0(sizeof(tvbparse_wanted_t));
tvbparse_wanted_t* w = g_new0(tvbparse_wanted_t, 1);
w->id = id;
w->condition = cond_end;

View File

@ -54,7 +54,7 @@ uat_t* uat_new(const char* name,
uat_reset_cb_t reset_cb,
uat_field_t* flds_array) {
/* Create new uat */
uat_t* uat = (uat_t *)g_malloc(sizeof(uat_t));
uat_t* uat = g_new(uat_t, 1);
guint i;
/* Add to global array of uats */
@ -96,7 +96,7 @@ uat_t* uat_new(const char* name,
uat->flags = flags;
for (i=0;flds_array[i].title;i++) {
fld_data_t* f = (fld_data_t *)g_malloc(sizeof(fld_data_t));
fld_data_t* f = g_new(fld_data_t, 1);
f->colnum = i+1;
f->rep = NULL;

View File

@ -417,7 +417,7 @@ static void wslua_add_plugin(const gchar *name, const gchar *version, const gcha
wslua_plugin *new_plug, *lua_plug;
lua_plug = wslua_plugin_list;
new_plug = (wslua_plugin *)g_malloc(sizeof(wslua_plugin));
new_plug = g_new(wslua_plugin, 1);
if (!lua_plug) { /* the list is empty */
wslua_plugin_list = new_plug;

View File

@ -30,7 +30,7 @@
/* create and set the wtap->priv private data for the file instance */
void create_wth_priv(lua_State* L, wtap *wth) {
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
file_priv_t *priv = g_new(file_priv_t, 1);
if (wth->priv != NULL) {
g_free(priv);
@ -107,7 +107,7 @@ void remove_wth_priv(lua_State* L, wtap *wth) {
/* create and set the wtap_dumper->priv private data for the file instance */
void create_wdh_priv(lua_State* L, wtap_dumper *wdh) {
file_priv_t *priv = (file_priv_t*)g_malloc(sizeof(file_priv_t));
file_priv_t *priv = g_new(file_priv_t, 1);
if (wdh->priv != NULL) {
g_free(priv);

View File

@ -741,7 +741,7 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) {
fh->finfo.additional_file_extensions = extra_extensions;
}
fh->finfo.can_write_encap = wslua_dummy_can_write_encap;
fh->finfo.wslua_info = (wtap_wslua_file_info_t*) g_malloc0(sizeof(wtap_wslua_file_info_t));
fh->finfo.wslua_info = g_new0(wtap_wslua_file_info_t, 1);
fh->finfo.wslua_info->wslua_can_write_encap = wslua_filehandler_can_write_encap;
fh->finfo.wslua_info->wslua_data = (void*)(fh);
fh->finfo.dump_open = wslua_filehandler_dump_open;

View File

@ -98,7 +98,7 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in o
return 0;
}
md = (struct _lua_menu_data *)g_malloc(sizeof(struct _lua_menu_data));
md = g_new(struct _lua_menu_data, 1);
md->L = L;
lua_pushvalue(L, 2);
@ -277,7 +277,7 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /*
}
dcbd = (struct _dlg_cb_data *)g_malloc(sizeof(struct _dlg_cb_data));
dcbd = g_new(struct _dlg_cb_data, 1);
dcbd->L = L;
lua_remove(L,1);
@ -565,11 +565,11 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /*
}
title = luaL_optstring(L,WSLUA_OPTARG_TextWindow_new_TITLE, "Untitled Window");
tw = (struct _wslua_tw *)g_malloc(sizeof(struct _wslua_tw));
tw = g_new(struct _wslua_tw, 1);
tw->expired = FALSE;
tw->ws_tw = ops->new_text_window(title);
default_cbd = (struct _close_cb_data *)g_malloc(sizeof(struct _close_cb_data));
default_cbd = g_new(struct _close_cb_data, 1);
default_cbd->L = NULL;
default_cbd->func_ref = 0;
@ -602,7 +602,7 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil
return 0;
}
cbd = (struct _close_cb_data *)g_malloc(sizeof(struct _close_cb_data));
cbd = g_new(struct _close_cb_data, 1);
cbd->L = L;
cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
@ -804,8 +804,8 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) {
lua_settop(L,3);
if (ops->add_button) {
fbt = (funnel_bt_t *)g_malloc(sizeof(funnel_bt_t));
cbd = (wslua_bt_cb_t *)g_malloc(sizeof(wslua_bt_cb_t));
fbt = g_new(funnel_bt_t, 1);
cbd = g_new(wslua_bt_cb_t, 1);
fbt->tw = tw->ws_tw;
fbt->func = wslua_button_callback;

View File

@ -87,7 +87,7 @@ static int new_pref(lua_State* L, pref_type_t type) {
const gchar* label = luaL_optstring(L,1,NULL);
const gchar* descr = luaL_optstring(L,3,"");
Pref pref = (wslua_pref_t *)g_malloc0(sizeof(wslua_pref_t));
Pref pref = g_new0(wslua_pref_t, 1);
pref->label = g_strdup(label);
pref->desc = g_strdup(descr);
pref->type = type;

View File

@ -109,7 +109,7 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,`
return 0;
}
proto = (wslua_proto_t *)g_malloc(sizeof(wslua_proto_t));
proto = g_new(wslua_proto_t, 1);
proto->name = hiname;
proto->loname = loname;

View File

@ -411,7 +411,7 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
lua_pop(L, 1);
}
tfs = (true_false_string *) g_malloc(sizeof(true_false_string));
tfs = g_new(true_false_string, 1);
tfs->true_string = true_string;
tfs->false_string = false_string;
@ -428,7 +428,7 @@ static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) {
return NULL;
}
units = (unit_name_string *) g_malloc0(sizeof(unit_name_string));
units = g_new0(unit_name_string, 1);
lua_pushnil(L);

View File

@ -28,7 +28,7 @@ static GPtrArray* outstanding_TreeItem = NULL;
/* pushing a TreeItem with a NULL item or subtree is completely valid for this function */
TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item) {
TreeItem ti = (struct _wslua_treeitem *)g_malloc(sizeof(struct _wslua_treeitem));
TreeItem ti = g_new(struct _wslua_treeitem, 1);
ti->tree = tree;
ti->item = item;
@ -103,7 +103,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int
case FT_RELATIVE_TIME:
{
/* nstime_t will be g_free'd by Lua */
nstime_t *nstime = (nstime_t *) g_malloc0(sizeof(nstime_t));
nstime_t *nstime = g_new0(nstime_t, 1);
item = proto_tree_add_time_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
tvbr->offset, tvbr->len, encoding,
nstime, &endoff, &err);

View File

@ -512,7 +512,7 @@ WSLUA_FUNCTION wslua_register_stat_cmd_arg(lua_State* L) {
#define WSLUA_ARG_register_stat_cmd_arg_ARGUMENT 1 /* The name of the option argument. */
#define WSLUA_OPTARG_register_stat_cmd_arg_ACTION 2 /* The function to be called when the command is invoked. */
const char* arg = luaL_checkstring(L,WSLUA_ARG_register_stat_cmd_arg_ARGUMENT);
statcmd_t* sc = (statcmd_t *)g_malloc0(sizeof(statcmd_t)); /* XXX leaked */
statcmd_t* sc = g_new0(statcmd_t, 1); /* XXX leaked */
stat_tap_ui ui_info;
sc->L = L;

4
file.c
View File

@ -2562,8 +2562,8 @@ cf_print_packets(capture_file *cf, print_args_t *print_args,
width of the title and the width of the data - and construct
a buffer with a line containing the column titles. */
callback_args.num_visible_cols = num_visible_col;
callback_args.col_widths = (gint *) g_malloc(sizeof(gint) * num_visible_col);
callback_args.visible_cols = (gint *) g_malloc(sizeof(gint) * num_visible_col);
callback_args.col_widths = g_new(gint, num_visible_col);
callback_args.visible_cols = g_new(gint, num_visible_col);
cp = &callback_args.header_line_buf[0];
line_len = 0;
visible_col_count = 0;

View File

@ -222,7 +222,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
/* Show statistics if they are valid */
if( result == 0 ) {
entry = (fileset_entry *)g_malloc(sizeof(fileset_entry));
entry = g_new(fileset_entry, 1);
entry->fullname = g_strdup(path);
entry->name = g_strdup(fname);

View File

@ -67,7 +67,7 @@ frame_cache(struct tvb_frame *frame_tvb)
if (buffer_cache->len > 0) {
frame_tvb->buf = (struct Buffer *) g_ptr_array_remove_index(buffer_cache, buffer_cache->len - 1);
} else {
frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
frame_tvb->buf = g_new(struct Buffer, 1);
}
ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);

View File

@ -24,7 +24,7 @@ codec_sbc_init(void)
{
sbc_t *sbc;
sbc = (sbc_t *) g_malloc(sizeof(sbc_t));
sbc = g_new(sbc_t, 1);
sbc_init(sbc, 0L);
return sbc;

View File

@ -124,7 +124,7 @@ void initialize_mate_runtime(mate_config* mc) {
if (mc) {
if (rd == NULL ) {
rd = (mate_runtime_data *)g_malloc(sizeof(mate_runtime_data));
rd = g_new(mate_runtime_data, 1);
} else {
g_hash_table_foreach(mc->pducfgs,destroy_pdus_in_cfg,NULL);
g_hash_table_foreach(mc->gopcfgs,destroy_gops_in_cfg,NULL);
@ -322,7 +322,7 @@ static void reanalyze_gop(mate_config* mc, mate_gop* gop) {
if (( gogkey_match = new_avpl_pairs_match(gop_cfg->name, gog->avpl, curr_gogkey, TRUE, FALSE) )) {
gog_key = (gogkey *)g_malloc(sizeof(gogkey));
gog_key = g_new(gogkey, 1);
gog_key->key = avpl_to_str(gogkey_match);
delete_avpl(gogkey_match,FALSE);
@ -734,7 +734,7 @@ static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto,
data.tree = tree;
/* first we create the proto range */
proto_range = (mate_range *)g_malloc(sizeof(mate_range));
proto_range = g_new(mate_range, 1);
proto_range->start = proto->start;
proto_range->end = proto->start + proto->length;
g_ptr_array_add(data.ranges,proto_range);

View File

@ -31,7 +31,7 @@ static void report_error(mate_config* mc, const gchar* fmt, ...) {
is going to be called only by the grammar
which will set all those elements that aren't set here */
extern mate_cfg_pdu* new_pducfg(mate_config* mc, gchar* name) {
mate_cfg_pdu* cfg = (mate_cfg_pdu *)g_malloc(sizeof(mate_cfg_pdu));
mate_cfg_pdu* cfg = g_new(mate_cfg_pdu, 1);
cfg->name = g_strdup(name);
cfg->last_id = 0;
@ -62,7 +62,7 @@ extern mate_cfg_pdu* new_pducfg(mate_config* mc, gchar* name) {
}
extern mate_cfg_gop* new_gopcfg(mate_config* mc, gchar* name) {
mate_cfg_gop* cfg = (mate_cfg_gop *)g_malloc(sizeof(mate_cfg_gop));
mate_cfg_gop* cfg = g_new(mate_cfg_gop, 1);
cfg->name = g_strdup(name);
cfg->last_id = 0;
@ -146,7 +146,7 @@ extern gboolean add_hfid(mate_config* mc, header_field_info* hfi, gchar* how, G
while (hfi) {
exists = TRUE;
ip = (int *)g_malloc(sizeof(int));
ip = g_new(int, 1);
*ip = hfi->id;
@ -189,7 +189,7 @@ extern gchar* add_ranges(mate_config* mc, gchar* range,GPtrArray* range_ptr_arr)
for (i=0; ranges[i]; i++) {
hfi = proto_registrar_get_byname(ranges[i]);
if (hfi) {
hfidp = (int *)g_malloc(sizeof(int));
hfidp = g_new(int, 1);
*hfidp = hfi->id;
g_ptr_array_add(range_ptr_arr,(gpointer)hfidp);
} else {
@ -206,7 +206,7 @@ extern gchar* add_ranges(mate_config* mc, gchar* range,GPtrArray* range_ptr_arr)
#endif
static void new_attr_hfri(mate_config* mc, gchar* item_name, GHashTable* hfids, gchar* name) {
int* p_id = (int *)g_malloc(sizeof(int));
int* p_id = g_new(int, 1);
hf_register_info hfri;
memset(&hfri, 0, sizeof hfri);
@ -575,7 +575,7 @@ extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) {
gint* ett;
avp_init();
mc = (mate_config *)g_malloc(sizeof(mate_config));
mc = g_new(mate_config, 1);
mc->hfid_mate = mate_hfid;

View File

@ -78,7 +78,7 @@ static void destroy_scs_collection(SCS_collection* c) {
}
static SCS_collection* scs_init(void) {
SCS_collection* c = (SCS_collection *)g_malloc(sizeof(SCS_collection));
SCS_collection* c = g_new(SCS_collection, 1);
c->hash = g_hash_table_new(g_str_hash,g_str_equal);

View File

@ -134,7 +134,7 @@ usbdump_open(wtap *wth, int *err, char **err_info)
}
/* Create a private structure to track the multiframe */
usbdump_info = (usbdump_info_t *)g_malloc(sizeof(usbdump_info_t));
usbdump_info = g_new(usbdump_info_t, 1);
usbdump_info->version = GUINT16_FROM_BE(version);
usbdump_info->multiframe_size = GUINT32_FROM_LE(multiframe_size);
usbdump_info->multiframe_overrun = FALSE;

View File

@ -1300,7 +1300,7 @@ protocolinfo_init(char *field)
ftenum_to_string(hfi),
hfibuf);
rs=(pci_t *)g_malloc(sizeof(pci_t));
rs=g_new(pci_t, 1);
rs->hf_index=hfi->id;
rs->filter=field;
rs->cmd_line_index = g_cmd_line_index++;
@ -1327,7 +1327,7 @@ protocolinfo_init(char *field)
static void
add_string_fmt(string_fmt_e format, gchar *plain) {
string_fmt_t *sf = (string_fmt_t *)g_malloc(sizeof(string_fmt_t));
string_fmt_t *sf = g_new(string_fmt_t, 1);
sf->format = format;
sf->plain = g_strdup(plain);

View File

@ -324,7 +324,7 @@ ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_acce
rb_data.num_files = 1;
}
rb_data.files = (rb_file *)g_malloc(rb_data.num_files * sizeof(rb_file));
rb_data.files = g_new(rb_file, rb_data.num_files);
if (rb_data.files == NULL) {
return -1;
}

View File

@ -204,7 +204,7 @@ sharkd_session_filter_data(const char *filter)
if (ret == -1)
return NULL;
l = (struct sharkd_filter_item *) g_malloc(sizeof(struct sharkd_filter_item));
l = g_new(struct sharkd_filter_item, 1);
l->filtered = filtered;
g_hash_table_insert(filter_table, g_strdup(filter), l);
@ -1339,7 +1339,7 @@ sharkd_session_packet_tap_rtp_analyse_cb(void *tapdata, packet_info *pinfo, epan
rtppacket_analyse(statinfo, pinfo, rtp_info);
item = (struct sharkd_analyse_rtp_items *) g_malloc(sizeof(struct sharkd_analyse_rtp_items));
item = g_new(struct sharkd_analyse_rtp_items, 1);
if (!rtp_req->packets)
rtp_req->start_time = nstime_to_sec(&pinfo->abs_ts);
@ -2296,7 +2296,7 @@ sharkd_session_process_tap(char *buf, const jsmntok_t *tokens, int count)
ct_tapname = proto_get_protocol_filter_name(get_conversation_proto_id(ct));
ct_data = (struct sharkd_conv_tap_data *) g_malloc0(sizeof(struct sharkd_conv_tap_data));
ct_data = g_new0(struct sharkd_conv_tap_data, 1);
ct_data->type = tok_tap;
ct_data->hash.user_data = ct_data;
@ -2957,7 +2957,7 @@ sharkd_iograph_packet(void *g, packet_info *pinfo, epan_dissect_t *edt, const vo
}
else if (graph->items == NULL)
{
graph->items = (io_graph_item_t *) g_malloc(sizeof(io_graph_item_t) * graph->space_items);
graph->items = g_new(io_graph_item_t, graph->space_items);
reset_io_graph_items(graph->items, graph->space_items);
}

View File

@ -0,0 +1,125 @@
"""
Detect and replace instances of g_malloc() and wmem_alloc() with
g_new() wmem_new(), to improve the readability of Wireshark's code.
Also detect and replace instances of
g_malloc(sizeof(struct myobj) * foo)
with:
g_new(struct myobj, foo)
to better prevent integer overflows
SPDX-License-Identifier: MIT
"""
import os
import re
import sys
print_replacement_info = True
patterns = [
# Replace (myobj *)g_malloc(sizeof(myobj)) with g_new(myobj, 1)
(re.compile(r'\(([^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(sizeof\s*\(\1\)\)'), r'g_new\2(\1, 1)'),
# Replace (struct myobj *)g_malloc(sizeof(struct myobj)) with g_new(struct myobj, 1)
(re.compile(r'\((struct\s*[^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(sizeof\s*\(\1\)\)'), r'g_new\2(\1, 1)'),
# Replace (myobj *)g_malloc(sizeof(myobj) * foo) with g_new(myobj, foo)
(re.compile(r'\(([^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(sizeof\s*\(\1\)\s*\*\s*([^\s]+)\)'), r'g_new\2(\1, \3)'),
# Replace (struct myobj *)g_malloc(sizeof(struct myobj) * foo) with g_new(struct myobj, foo)
(re.compile(r'\((struct\s*[^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(sizeof\s*\(\1\)\s*\*\s*([^\s]+)\)'), r'g_new\2(\1, \3)'),
# Replace (myobj *)g_malloc(foo * sizeof(myobj)) with g_new(myobj, foo)
(re.compile(r'\(([^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(([^\s]+)\s*\*\s*sizeof\s*\(\1\)\)'), r'g_new\2(\1, \3)'),
# Replace (struct myobj *)g_malloc(foo * sizeof(struct myobj)) with g_new(struct myobj, foo)
(re.compile(r'\((struct\s*[^\s\*]+)\s*\*\)\s*g_malloc(0?)\s*\(([^\s]+)\s*\*\s*sizeof\s*\(\1\)\)'), r'g_new\2(\1, \3)'),
# Replace (myobj *)wmem_alloc(wmem_file_scope(), sizeof(myobj)) with wmem_new(wmem_file_scope(), myobj)
(re.compile(r'\(([^\s\*]+)\s*\*\)\s*wmem_alloc(0?)\s*\(\s*([_a-z\(\)->]+),\s*sizeof\s*\(\1\)\)'), r'wmem_new\2(\3, \1)'),
# Replace (struct myobj *)wmem_alloc(wmem_file_scope(), sizeof(struct myobj)) with wmem_new(wmem_file_scope(), struct myobj)
(re.compile(r'\((struct\s+[^\s\*]+)\s*\*\)\s*wmem_alloc(0?)\s*\(\s*([_a-z\(\)->]+),\s*sizeof\s*\(\1\)\)'), r'wmem_new\2(\3, \1)'),
]
def replace_file(fpath):
with open(fpath, 'r') as fh:
fdata_orig = fh.read()
fdata = fdata_orig
for pattern, replacewith in patterns:
fdata_out = pattern.sub(replacewith, fdata)
if print_replacement_info and fdata != fdata_out:
for match in re.finditer(pattern, fdata):
replacement = re.sub(pattern, replacewith, match.group(0))
print("Bad malloc pattern in %s: Replace '%s' with '%s'" % (fpath, match.group(0), replacement))
fdata = fdata_out
if fdata_out != fdata_orig:
with open(fpath, 'w') as fh:
fh.write(fdata_out)
return fdata_out
def run_specific_files(fpaths):
for fpath in fpaths:
if not (fpath.endswith('.c') or fpath.endswith('.cpp')):
continue
replace_file(fpath)
def run_recursive(root_dir):
for root, dirs, files in os.walk(root_dir):
fpaths = []
for fname in files:
fpath = os.path.join(root, fname)
fpaths.append(fpath)
run_specific_files(fpaths)
def test_replacements():
test_string = """\
(if_info_t*) g_malloc0(sizeof(if_info_t))
(oui_info_t *)g_malloc(sizeof (oui_info_t))
(guint8 *)g_malloc(16 * sizeof(guint8))
(guint32 *)g_malloc(sizeof(guint32)*2)
(struct imf_field *)g_malloc (sizeof (struct imf_field))
(proto_data_t *)wmem_alloc(scope, sizeof(proto_data_t))
(giop_sub_handle_t *)wmem_alloc(wmem_epan_scope(), sizeof (giop_sub_handle_t))
(mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t))
(dcerpc_bind_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_value))
(dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
(struct smtp_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct smtp_session_state))
(struct batman_packet_v5 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v5))
"""
expected_output = """\
g_new0(if_info_t, 1)
g_new(oui_info_t, 1)
g_new(guint8, 16)
g_new(guint32, 2)
g_new(struct imf_field, 1)
wmem_new(scope, proto_data_t)
wmem_new(wmem_epan_scope(), giop_sub_handle_t)
wmem_new0(pinfo->pool, mtp3_addr_pc_t)
wmem_new(wmem_file_scope(), dcerpc_bind_value)
wmem_new(wmem_file_scope(), dcerpc_matched_key);
wmem_new0(wmem_file_scope(), struct smtp_session_state)
wmem_new(wmem_packet_scope(), struct batman_packet_v5)
"""
output = test_string
for pattern, replacewith in patterns:
output = pattern.sub(replacewith, output)
assert(output == expected_output)
def main():
test_replacements()
if len(sys.argv) == 2:
root_dir = sys.argv[1]
run_recursive(root_dir)
else:
fpaths = []
for line in sys.stdin:
line = line.strip()
if line:
fpaths.append(line)
run_specific_files(fpaths)
if __name__ == "__main__":
main()

View File

@ -68,6 +68,9 @@ else
CHECK_FILES="$COMMIT_FILES"
fi
bad_alloc_patterns=${PWD}/tools/detect_bad_alloc_patterns.py
echo "$COMMIT_FILES" | $PYBIN "$bad_alloc_patterns"
# On windows python will output \r\n line endings - we don't want that.
#
# Do not use sed, as not all versions of sed support \r as meaning CR

View File

@ -84,7 +84,7 @@ capture_callback_add(capture_callback_t func, gpointer user_data)
{
capture_callback_data_t *cb;
cb = (capture_callback_data_t *)g_malloc(sizeof(capture_callback_data_t));
cb = g_new(capture_callback_data_t, 1);
cb->cb_fct = func;
cb->user_data = user_data;
@ -860,7 +860,7 @@ capture_stat_start(capture_options *capture_opts)
for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = &g_array_index(capture_opts->all_ifaces, interface_t, i);
if (device->type != IF_PIPE) {
sc_item = (if_stat_cache_item_t *)g_malloc0(sizeof(if_stat_cache_item_t));
sc_item = g_new0(if_stat_cache_item_t, 1);
g_assert(device->if_info.name);
sc_item->name = g_strdup(device->if_info.name);
sc->cache_list = g_list_prepend(sc->cache_list, sc_item);

View File

@ -115,7 +115,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *du
* struct will be created for it. */
rt = relative_time;
while (rt >= it->start_time + parent->interval) {
it->next = (io_stat_item_t *)g_malloc(sizeof(io_stat_item_t));
it->next = g_new(io_stat_item_t, 1);
it->next->prev = it;
it->next->next = NULL;
it = it->next;
@ -572,7 +572,7 @@ iostat_draw(void *arg)
mit = (io_stat_item_t *)arg;
iot = mit->parent;
num_cols = iot->num_cols;
col_w = (column_width *)g_malloc(sizeof(column_width) * num_cols);
col_w = g_new(column_width, num_cols);
fmts = (char **)g_malloc(sizeof(char *) * num_cols);
duration = ((guint64)cfile.elapsed_time.secs * G_GUINT64_CONSTANT(1000000)) +
(guint64)((cfile.elapsed_time.nsecs + 500) / 1000);
@ -1423,7 +1423,7 @@ iostat_init(const char *opt_arg, void *userdata _U_)
break;
}
io = (io_stat_t *)g_malloc(sizeof(io_stat_t));
io = g_new(io_stat_t, 1);
/* If interval is 0, calculate statistics over the whole file by setting the interval to
* G_MAXUINT64 */
@ -1484,10 +1484,10 @@ iostat_init(const char *opt_arg, void *userdata _U_)
}
}
io->items = (io_stat_item_t *)g_malloc(sizeof(io_stat_item_t) * io->num_cols);
io->items = g_new(io_stat_item_t, io->num_cols);
io->filters = (const char **)g_malloc(sizeof(char *) * io->num_cols);
io->max_vals = (guint64 *)g_malloc(sizeof(guint64) * io->num_cols);
io->max_frame = (guint32 *)g_malloc(sizeof(guint32) * io->num_cols);
io->max_vals = g_new(guint64, io->num_cols);
io->max_frame = g_new(guint32, io->num_cols);
for (i=0; i<io->num_cols; i++) {
io->max_vals[i] = 0;

View File

@ -190,7 +190,7 @@ sctpstat_init(const char *opt_arg, void *userdata _U_)
sctpstat_t *hs;
GString *error_string;
hs = (sctpstat_t *)g_malloc(sizeof(sctpstat_t));
hs = g_new(sctpstat_t, 1);
if (!strncmp(opt_arg, "sctp,stat,", 11)) {
hs->filter = g_strdup(opt_arg+11);
} else {

View File

@ -45,7 +45,7 @@ add_filter_entry(GList *fl, const char *filt_name, const char *filt_expr)
{
filter_def *filt;
filt = (filter_def *) g_malloc(sizeof(filter_def));
filt = g_new(filter_def, 1);
filt->name = g_strdup(filt_name);
filt->strval = g_strdup(filt_expr);
return g_list_prepend(fl, filt);

View File

@ -227,7 +227,7 @@ scan_local_interfaces(void (*update_cb)(void))
monitor_mode = prefs_capture_device_monitor_mode(if_info->name);
caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, update_cb);
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t));
temp_addr = g_new0(if_addr_t, 1);
if (ips != 0) {
g_string_append(ip_str, "\n");
}
@ -290,7 +290,7 @@ scan_local_interfaces(void (*update_cb)(void))
*/
for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
data_link_info = (data_link_info_t *)lt_entry->data;
link = (link_row *)g_malloc(sizeof(link_row));
link = g_new(link_row, 1);
if (data_link_info->description != NULL) {
link->dlt = data_link_info->dlt;
link->name = g_strdup(data_link_info->description);

View File

@ -196,7 +196,7 @@ mcaststream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
tmp_strinfo.total_bytes = 0;
/* reset slidingwindow and buffer parameters */
tmp_strinfo.element.buff = (nstime_t *)g_malloc(buffsize * sizeof(nstime_t));
tmp_strinfo.element.buff = g_new(nstime_t, buffsize);
tmp_strinfo.element.first=0;
tmp_strinfo.element.last=0;
tmp_strinfo.element.burstsize=1;
@ -210,16 +210,16 @@ mcaststream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
tmp_strinfo.element.buffstatus=0;
tmp_strinfo.element.maxbw=0;
strinfo = (mcast_stream_info_t *)g_malloc(sizeof(mcast_stream_info_t));
strinfo = g_new(mcast_stream_info_t, 1);
*strinfo = tmp_strinfo; /* memberwise copy of struct */
tapinfo->strinfo_list = g_list_append(tapinfo->strinfo_list, strinfo);
strinfo->element.buff = (nstime_t *)g_malloc(buffsize * sizeof(nstime_t));
strinfo->element.buff = g_new(nstime_t, buffsize);
/* set time with the first packet */
if (tapinfo->npackets == 0) {
tapinfo->allstreams = (mcast_stream_info_t *)g_malloc(sizeof(mcast_stream_info_t));
tapinfo->allstreams = g_new(mcast_stream_info_t, 1);
tapinfo->allstreams->element.buff =
(nstime_t *)g_malloc(buffsize * sizeof(nstime_t));
g_new(nstime_t, buffsize);
tapinfo->allstreams->start_rel = pinfo->rel_ts;
tapinfo->allstreams->total_bytes = 0;
tapinfo->allstreams->element.first=0;

View File

@ -164,7 +164,7 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields
fmt_data *cfmt, *last_cfmt;
gint colnr;
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt = g_new(fmt_data, 1);
/*
* Because a single underscore is interpreted as a signal that the next character
* is going to be marked as accelerator for this header (i.e. is going to be

View File

@ -45,7 +45,7 @@ add_profile_entry(GList *fl, const char *profilename, const char *reference, int
{
profile_def *profile;
profile = (profile_def *) g_malloc0(sizeof(profile_def));
profile = g_new0(profile_def, 1);
profile->name = g_strdup(profilename);
profile->reference = g_strdup(reference);
profile->status = status;

View File

@ -214,7 +214,7 @@ window_geom_save(const gchar *name, window_geometry_t *geom)
}
/* g_malloc and insert the new one */
work = (window_geometry_t *)g_malloc(sizeof(window_geometry_t));
work = g_new(window_geometry_t, 1);
*work = *geom;
key = g_strdup(name);
work->key = key;
@ -1155,7 +1155,7 @@ read_set_recent_pair_static(gchar *key, const gchar *value,
col_l_elt = g_list_first(col_l);
while (col_l_elt) {
gchar *fmt = g_strdup((const gchar *)col_l_elt->data);
cfmt = (col_width_data *) g_malloc(sizeof(col_width_data));
cfmt = g_new(col_width_data, 1);
if (strncmp(fmt, cust_format, cust_format_len) != 0) {
cfmt->cfmt = get_column_format_from_str(fmt);
cfmt->cfield = NULL;
@ -1511,7 +1511,7 @@ recent_set_column_width(gint col, gint width)
}
if (!found) {
col_w = (col_width_data *) g_malloc(sizeof(col_width_data));
col_w = g_new(col_width_data, 1);
col_w->cfmt = cfmt;
col_w->cfield = g_strdup(cfield);
col_w->width = width;
@ -1577,7 +1577,7 @@ recent_set_column_xalign(gint col, gchar xalign)
}
if (!found) {
col_w = (col_width_data *) g_malloc(sizeof(col_width_data));
col_w = g_new(col_width_data, 1);
col_w->cfmt = cfmt;
col_w->cfield = g_strdup(cfield);
col_w->width = 40;

View File

@ -182,7 +182,7 @@ static tap_packet_status rlc_lte_tap_for_graph_data(void *pct, packet_info *pinf
rlchdr->isControlPDU)) {
/* It matches. Copy segment details out of tap struct */
struct rlc_segment *segment = (struct rlc_segment *)g_malloc(sizeof(struct rlc_segment));
struct rlc_segment *segment = g_new(struct rlc_segment, 1);
segment->next = NULL;
segment->num = pinfo->num;
segment->rel_secs = (guint32) pinfo->rel_ts.secs;

View File

@ -57,7 +57,7 @@ rtpstream_info_t *rtpstream_info_malloc_and_init(void)
{
rtpstream_info_t *dest;
dest = (rtpstream_info_t *)g_malloc(sizeof(rtpstream_info_t));
dest = g_new(rtpstream_info_t, 1);
rtpstream_info_init(dest);
return dest;
@ -80,7 +80,7 @@ rtpstream_info_t *rtpstream_info_malloc_and_copy_deep(const rtpstream_info_t *sr
{
rtpstream_info_t *dest;
dest = (rtpstream_info_t *)g_malloc(sizeof(rtpstream_info_t));
dest = g_new(rtpstream_info_t, 1);
rtpstream_info_copy_deep(dest, src);
return dest;

View File

@ -326,7 +326,7 @@ add_to_graph(voip_calls_tapinfo_t *tapinfo, packet_info *pinfo, epan_dissect_t *
return;
}
gai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
gai = g_new0(seq_analysis_item_t, 1);
gai->frame_number = pinfo->num;
copy_address(&(gai->src_addr),src_addr);
copy_address(&(gai->dst_addr),dst_addr);
@ -446,7 +446,7 @@ static void insert_to_graph_t38(voip_calls_tapinfo_t *tapinfo, packet_info *pinf
gboolean inserted;
gchar time_str[COL_MAX_LEN];
new_gai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
new_gai = g_new0(seq_analysis_item_t, 1);
new_gai->frame_number = frame_num;
copy_address(&(new_gai->src_addr),src_addr);
copy_address(&(new_gai->dst_addr),dst_addr);
@ -731,7 +731,7 @@ rtp_draw(void *tap_offset_ptr)
(rtp_listinfo->is_srtp)?"SRTP":"RTP", rtp_listinfo->packet_count,
duration/1000,(duration%1000), rtp_listinfo->id.ssrc);
} else {
new_gai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
new_gai = g_new0(seq_analysis_item_t, 1);
new_gai->frame_number = rtp_listinfo->start_fd->num;
copy_address(&(new_gai->src_addr),&(rtp_listinfo->id.src_addr));
copy_address(&(new_gai->dst_addr),&(rtp_listinfo->id.dst_addr));
@ -940,7 +940,7 @@ t38_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt, const
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
callsinfo->from_identity=g_strdup("T38 Media only");
@ -1135,7 +1135,7 @@ sip_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt ,
if (tapinfo->fs_option == FLOW_ALL ||
(tapinfo->fs_option == FLOW_ONLY_INVITES &&
strcmp(pi->request_method,"INVITE")==0)) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup(pi->tap_from_addr);
@ -1373,7 +1373,7 @@ isup_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
-i.e. if this session is a call*/
if ((callsinfo==NULL) &&(pi->message_type==1)) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
copy_address(&(callsinfo->initial_speaker),&(pinfo->src));
@ -1789,7 +1789,7 @@ q931_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
/* if it is a new call, add it to the list */
if (!callsinfo) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup(tapinfo->q931_calling_number);
@ -2007,7 +2007,7 @@ h225_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
callsinfo->from_identity=g_strdup("");
@ -2059,7 +2059,7 @@ h225_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
/* this is still IPv4 only, because the dissector is */
if (pi->is_h245 == TRUE) {
h245_add = (h245_address_t *)g_malloc(sizeof (h245_address_t));
h245_add = g_new(h245_address_t, 1);
alloc_address_wmem(NULL, &h245_add->h245_address, AT_IPv4, 4, &pi->h245_address);
h245_add->h245_port = pi->h245_port;
add_h245_Address(tmp_h323info, h245_add);
@ -2650,7 +2650,7 @@ mgcp_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
if (fromEndpoint) {
@ -2863,7 +2863,7 @@ actrace_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *e
/* if it is a new call, add it to the list */
if (!callsinfo) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup("N/A");
@ -2997,7 +2997,7 @@ h248_calls_packet_common(voip_calls_tapinfo_t *tapinfo, packet_info *pinfo, epan
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->from_identity = g_strdup_printf("%s : %.8x", mgw_addr, cmd->ctx->id);
@ -3161,7 +3161,7 @@ sccp_calls(voip_calls_tapinfo_t *tapinfo, packet_info *pinfo, epan_dissect_t *ed
}
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->call_active_state = VOIP_ACTIVE;
if ( assoc->calling_party ) {
@ -3404,7 +3404,7 @@ unistim_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *e
/* If new add to list */
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup_printf("%x",pi->termid);
@ -3660,7 +3660,7 @@ unistim_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *e
* ineffective.
* Sometimes calls start immediately with open stream.
*/
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup("UNKNOWN");
@ -3893,7 +3893,7 @@ skinny_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *ed
phone = &(pinfo->src);
if (callsinfo==NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
/* callsinfo->from_identity = g_strdup_printf("%s : %.8x", "Skinny", 1); */
@ -4049,7 +4049,7 @@ iax2_calls_packet( void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt
/* We only care about real calls, i.e., no registration stuff */
if (ii->ftype != AST_FRAME_IAX || ii->csub != IAX_COMMAND_NEW)
return TAP_PACKET_DONT_REDRAW;
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->prot_info=g_malloc(sizeof(iax2_info_t));
@ -4173,7 +4173,7 @@ voip_calls_packet(void *tap_offset_ptr, packet_info *pinfo, epan_dissect_t *edt,
}
if (callsinfo == NULL) {
callsinfo = (voip_calls_info_t *)g_malloc0(sizeof(voip_calls_info_t));
callsinfo = g_new0(voip_calls_info_t, 1);
callsinfo->call_active_state = pi->call_active_state;
callsinfo->call_state = pi->call_state;
callsinfo->call_id=g_strdup((pi->call_id)?pi->call_id:"");

View File

@ -335,7 +335,7 @@ gboolean _5views_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
/* This is a 5Views file */
wdh->subtype_write = _5views_dump;
wdh->subtype_finish = _5views_dump_finish;
_5views = (_5views_dump_t *)g_malloc(sizeof(_5views_dump_t));
_5views = g_new(_5views_dump_t, 1);
wdh->priv = (void *)_5views;
_5views->nframes = 0;

View File

@ -131,7 +131,7 @@ wtap_open_return_val aethra_open(wtap *wth, int *err, gchar **err_info)
sizeof hdr - sizeof hdr.magic, err, err_info))
return WTAP_OPEN_ERROR;
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_AETHRA;
aethra = (aethra_t *)g_malloc(sizeof(aethra_t));
aethra = g_new(aethra_t, 1);
wth->priv = (void *)aethra;
wth->subtype_read = aethra_read;
wth->subtype_seek_read = aethra_seek_read;

View File

@ -267,7 +267,7 @@ wtap_open_return_val ascend_open(wtap *wth, int *err, gchar **err_info)
wth->snapshot_length = ASCEND_MAX_PKT_LEN;
wth->subtype_read = ascend_read;
wth->subtype_seek_read = ascend_seek_read;
ascend = (ascend_t *)g_malloc(sizeof(ascend_t));
ascend = g_new(ascend_t, 1);
wth->priv = (void *)ascend;
/* The first packet we want to read is the one that

View File

@ -199,7 +199,7 @@ wtap_open_return_val capsa_open(wtap *wth, int *err, gchar **err_info)
return WTAP_OPEN_ERROR;
wth->file_type_subtype = file_type_subtype;
capsa = (capsa_t *)g_malloc(sizeof(capsa_t));
capsa = g_new(capsa_t, 1);
capsa->format_indicator = format_indicator;
capsa->number_of_frames = number_of_frames;
capsa->frame_count = 0;

View File

@ -623,7 +623,7 @@ catapult_dct2000_dump(wtap_dumper *wdh, const wtap_rec *rec,
}
/* Allocate the dct2000-specific dump structure */
dct2000 = (dct2000_dump_t *)g_malloc(sizeof(dct2000_dump_t));
dct2000 = g_new(dct2000_dump_t, 1);
wdh->priv = (void *)dct2000;
/* Copy time of beginning of file */

View File

@ -109,7 +109,7 @@ wtap_open_return_val csids_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
csids = (csids_t *)g_malloc(sizeof(csids_t));
csids = g_new(csids_t, 1);
wth->priv = (void *)csids;
csids->byteswapped = byteswap;
wth->file_encap = WTAP_ENCAP_RAW_IP;

View File

@ -237,7 +237,7 @@ static struct erf_if_mapping* erf_if_mapping_create(guint64 host_id, guint8 sour
int i = 0;
struct erf_if_mapping *if_map = NULL;
if_map = (struct erf_if_mapping*) g_malloc0(sizeof(struct erf_if_mapping));
if_map = g_new0(struct erf_if_mapping, 1);
if_map->host_id = host_id;
if_map->source_id = source_id;
@ -259,7 +259,7 @@ erf_t *erf_priv_create(void)
{
erf_t *erf_priv;
erf_priv = (erf_t*) g_malloc(sizeof(erf_t));
erf_priv = g_new(erf_t, 1);
erf_priv->anchor_map = g_hash_table_new_full(erf_anchor_mapping_hash, erf_anchor_mapping_equal, erf_anchor_mapping_destroy, NULL);
erf_priv->if_map = g_hash_table_new_full(erf_if_mapping_hash, erf_if_mapping_equal, erf_if_mapping_destroy, NULL);
erf_priv->implicit_host_id = ERF_META_HOST_ID_IMPLICIT;
@ -993,7 +993,7 @@ static void erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_,
struct erf_meta_section *section_ptr = (struct erf_meta_section*) user_data;
struct erf_meta_tag *tag_ptr = NULL;
tag_ptr = (struct erf_meta_tag*) g_malloc0(sizeof(struct erf_meta_tag));
tag_ptr = g_new0(struct erf_meta_tag, 1);
switch(option_id) {
case OPT_SHB_USERAPPL:
@ -1025,7 +1025,7 @@ static void erf_write_wtap_option_to_host_tag(wtap_block_t block _U_,
struct erf_meta_section *section_ptr = (struct erf_meta_section*) user_data;
struct erf_meta_tag *tag_ptr = NULL;
tag_ptr = (struct erf_meta_tag*) g_malloc0(sizeof(struct erf_meta_tag));
tag_ptr = g_new0(struct erf_meta_tag, 1);
switch(option_id) {
case OPT_SHB_HARDWARE:
@ -1057,7 +1057,7 @@ static void erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_,
struct erf_meta_section *section_ptr = (struct erf_meta_section*) user_data;
struct erf_meta_tag *tag_ptr = NULL;
tag_ptr = (struct erf_meta_tag*) g_malloc0(sizeof(struct erf_meta_tag));
tag_ptr = g_new0(struct erf_meta_tag, 1);
switch(option_id) {
case OPT_COMMENT:
@ -1186,7 +1186,7 @@ static gboolean erf_wtap_blocks_to_erf_sections(wtap_block_t block, GPtrArray *s
struct erf_meta_section *section_ptr;
section_ptr = (struct erf_meta_section*) g_malloc(sizeof(struct erf_meta_section));
section_ptr = g_new(struct erf_meta_section, 1);
section_ptr->tags = g_ptr_array_new_with_free_func(erf_meta_tag_free);
section_ptr->type = section_type;
section_ptr->section_id = section_id;
@ -1275,13 +1275,13 @@ static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_ty
const gchar *user = NULL;
/* Generate the section */
section_ptr = (struct erf_meta_section*) g_malloc(sizeof(struct erf_meta_section));
section_ptr = g_new(struct erf_meta_section, 1);
section_ptr->type = section_type;
section_ptr->section_id = section_id;
section_ptr->tags = g_ptr_array_new_with_free_func(erf_meta_tag_free);
/* Generate the comment tag */
comment_tag_ptr = (struct erf_meta_tag*) g_malloc(sizeof(struct erf_meta_tag));
comment_tag_ptr = g_new(struct erf_meta_tag, 1);
comment_tag_ptr->type = ERF_META_TAG_comment;
/* XXX: if the comment has been cleared write the empty string (which
* conveniently is all a zero length tag which means the value is
@ -1293,7 +1293,7 @@ static gboolean erf_comment_to_sections(wtap_dumper *wdh _U_, guint16 section_ty
user = g_get_user_name();
if (user) {
/* Generate username tag */
user_tag_ptr = (struct erf_meta_tag*) g_malloc(sizeof(struct erf_meta_tag));
user_tag_ptr = g_new(struct erf_meta_tag, 1);
user_tag_ptr->type = ERF_META_TAG_user;
user_tag_ptr->value = (guint8*)g_strdup(user);
user_tag_ptr->length = (guint16)strlen((char*)user_tag_ptr->value);
@ -1733,7 +1733,7 @@ static gboolean erf_write_meta_record(wtap_dumper *wdh, erf_dump_t *dump_priv, g
static erf_dump_t *erf_dump_priv_create(void) {
erf_dump_t *dump_priv;
dump_priv = (erf_dump_t*)g_malloc(sizeof(erf_dump_t));
dump_priv = g_new(erf_dump_t, 1);
dump_priv->write_next_extra_meta = FALSE;
dump_priv->last_meta_periodic = FALSE;
dump_priv->gen_time = 0;
@ -2218,7 +2218,7 @@ static int erf_update_anchors_from_header(erf_t *erf_priv, wtap_rec *rec, union
*/
/* Only Provenance record can contain the information we need */
struct erf_anchor_mapping *mapping_ptr =
(struct erf_anchor_mapping*)g_malloc0(sizeof(struct erf_anchor_mapping));
g_new0(struct erf_anchor_mapping, 1);
/* May be ERF_META_HOST_ID_IMPLICIT */
mapping_ptr->host_id = host_id_current;
mapping_ptr->anchor_id = anchor_id_current;
@ -3079,7 +3079,7 @@ static int populate_anchor_info(erf_t *erf_priv, wtap *wth, union wtap_pseudo_he
else {
/* !lookup_result */
struct erf_anchor_mapping *new_mapping;
new_mapping = (struct erf_anchor_mapping *)g_malloc0(sizeof(struct erf_anchor_mapping));
new_mapping = g_new0(struct erf_anchor_mapping, 1);
new_mapping->anchor_id = mapping->anchor_id;
new_mapping->host_id = mapping->host_id;
new_mapping->gen_time = state->gen_time;

View File

@ -820,7 +820,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
}
errno = ENOMEM;
wth = (wtap *)g_malloc0(sizeof(wtap));
wth = g_new0(wtap, 1);
/* Open the file */
errno = WTAP_ERR_CANT_OPEN;
@ -2636,7 +2636,7 @@ wtap_dump_alloc_wdh(int file_type_subtype, int encap, int snaplen,
{
wtap_dumper *wdh;
wdh = (wtap_dumper *)g_malloc0(sizeof (wtap_dumper));
wdh = g_new0(wtap_dumper, 1);
if (wdh == NULL) {
*err = errno;
return NULL;

View File

@ -155,7 +155,7 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info)
/* Get capture start time */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_I4BTRACE;
i4btrace = (i4btrace_t *)g_malloc(sizeof(i4btrace_t));
i4btrace = g_new(i4btrace_t, 1);
wth->priv = (void *)i4btrace;
wth->subtype_read = i4btrace_read;
wth->subtype_seek_read = i4btrace_seek_read;

View File

@ -119,7 +119,7 @@ wtap_open_return_val iptrace_open(wtap *wth, int *err, gchar **err_info)
/* This is an iptrace file */
wth->subtype_close = iptrace_close;
iptrace = (iptrace_t *)g_malloc(sizeof(iptrace_t));
iptrace = g_new(iptrace_t, 1);
iptrace->interface_ids = g_hash_table_new(if_info_hash, if_info_equal);
iptrace->num_interface_ids = 0;
wth->priv = (void *)iptrace;
@ -137,7 +137,7 @@ static void iptrace_close(wtap *wth)
static void add_new_if_info(iptrace_t *iptrace, if_info *info, gpointer *result)
{
if_info *new_info = (if_info *)g_malloc(sizeof (if_info));
if_info *new_info = g_new(if_info, 1);
*new_info = *info;
*result = GUINT_TO_POINTER(iptrace->num_interface_ids);
g_hash_table_insert(iptrace->interface_ids, (gpointer)new_info, *result);

Some files were not shown because too many files have changed in this diff Show More