aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoshe Kaplan <me@moshekaplan.com>2020-12-20 21:30:28 -0500
committerAndersBroman <a.broman58@gmail.com>2020-12-22 14:56:38 +0000
commite16166a74cca1d66e2c302e257cf94aebb380599 (patch)
tree8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e
parent7b27b444cbd94853b399da770e0dad4b91ef23ac (diff)
Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing occurrences of `g_malloc()` and `wmem_alloc()` with `g_new()` and `wmem_new()`, to improve the readability of Wireshark's code, and occurrences of `g_malloc(sizeof(struct myobj) * foo)` with `g_new(struct myobj, foo)` to prevent integer overflows Also fixes all existing occurrences across the codebase.
-rw-r--r--capchild/capture_ifinfo.c8
-rw-r--r--caputils/airpcap_loader.c6
-rw-r--r--caputils/capture-pcap-util.c4
-rw-r--r--dumpcap.c8
-rw-r--r--editcap.c2
-rw-r--r--epan/color_filters.c4
-rw-r--r--epan/column.c8
-rw-r--r--epan/conversation_filter.c2
-rw-r--r--epan/crypt/dot11decrypt.c8
-rw-r--r--epan/disabled_protos.c4
-rw-r--r--epan/dissectors/packet-batadv.c68
-rw-r--r--epan/dissectors/packet-btmesh.c4
-rw-r--r--epan/dissectors/packet-dbus.c12
-rw-r--r--epan/dissectors/packet-dcerpc.c32
-rw-r--r--epan/dissectors/packet-dpaux.c3
-rw-r--r--epan/dissectors/packet-exported_pdu.c4
-rw-r--r--epan/dissectors/packet-fpp.c2
-rw-r--r--epan/dissectors/packet-giop.c8
-rw-r--r--epan/dissectors/packet-hpfeeds.c2
-rw-r--r--epan/dissectors/packet-idn.c4
-rw-r--r--epan/dissectors/packet-ieee802a.c2
-rw-r--r--epan/dissectors/packet-imf.c6
-rw-r--r--epan/dissectors/packet-infiniband.c4
-rw-r--r--epan/dissectors/packet-ipmi.c2
-rw-r--r--epan/dissectors/packet-ipsec.c2
-rw-r--r--epan/dissectors/packet-k12.c2
-rw-r--r--epan/dissectors/packet-mac-lte-framed.c2
-rw-r--r--epan/dissectors/packet-mswsp.c2
-rw-r--r--epan/dissectors/packet-mtp3.c4
-rw-r--r--epan/dissectors/packet-nano.c6
-rw-r--r--epan/dissectors/packet-nvme-tcp.c3
-rw-r--r--epan/dissectors/packet-radius.c8
-rw-r--r--epan/dissectors/packet-rpc.c2
-rw-r--r--epan/dissectors/packet-sctp.c10
-rw-r--r--epan/dissectors/packet-smb.c4
-rw-r--r--epan/dissectors/packet-smtp.c4
-rw-r--r--epan/dissectors/packet-snort-config.c4
-rw-r--r--epan/dissectors/packet-snort.c2
-rw-r--r--epan/dissectors/packet-soupbintcp.c6
-rw-r--r--epan/dissectors/packet-ssh.c2
-rw-r--r--epan/dissectors/packet-tpncp.c3
-rw-r--r--epan/dissectors/packet-twamp.c2
-rw-r--r--epan/dissectors/packet-umts_rlc.c12
-rw-r--r--epan/dissectors/packet-zvt.c3
-rw-r--r--epan/funnel.c4
-rw-r--r--epan/packet.c12
-rw-r--r--epan/plugin_if.c6
-rw-r--r--epan/prefs.c4
-rw-r--r--epan/print_stream.c4
-rw-r--r--epan/proto_data.c2
-rw-r--r--epan/srt_table.c2
-rw-r--r--epan/stat_tap_ui.c2
-rw-r--r--epan/stats_tree.c20
-rw-r--r--epan/tap.c4
-rw-r--r--epan/tvbparse.c4
-rw-r--r--epan/uat.c4
-rw-r--r--epan/wslua/init_wslua.c2
-rw-r--r--epan/wslua/wslua_file_common.c4
-rw-r--r--epan/wslua/wslua_file_handler.c2
-rw-r--r--epan/wslua/wslua_gui.c14
-rw-r--r--epan/wslua/wslua_pref.c2
-rw-r--r--epan/wslua/wslua_proto.c2
-rw-r--r--epan/wslua/wslua_proto_field.c4
-rw-r--r--epan/wslua/wslua_tree.c4
-rw-r--r--epan/wslua/wslua_util.c2
-rw-r--r--file.c4
-rw-r--r--fileset.c2
-rw-r--r--frame_tvbuff.c2
-rw-r--r--plugins/codecs/sbc/sbc.c2
-rw-r--r--plugins/epan/mate/mate_runtime.c6
-rw-r--r--plugins/epan/mate/mate_setup.c12
-rw-r--r--plugins/epan/mate/mate_util.c2
-rw-r--r--plugins/wiretap/usbdump/usbdump.c2
-rw-r--r--rawshark.c4
-rw-r--r--ringbuffer.c2
-rw-r--r--sharkd_session.c8
-rw-r--r--tools/detect_bad_alloc_patterns.py125
-rwxr-xr-xtools/pre-commit3
-rw-r--r--ui/capture.c4
-rw-r--r--ui/cli/tap-iostat.c12
-rw-r--r--ui/cli/tap-sctpchunkstat.c2
-rw-r--r--ui/filter_files.c2
-rw-r--r--ui/iface_lists.c4
-rw-r--r--ui/mcast_stream.c10
-rw-r--r--ui/preference_utils.c2
-rw-r--r--ui/profile.c2
-rw-r--r--ui/recent.c8
-rw-r--r--ui/tap-rlc-graph.c2
-rw-r--r--ui/tap-rtp-common.c4
-rw-r--r--ui/voip_calls.c36
-rw-r--r--wiretap/5views.c2
-rw-r--r--wiretap/aethra.c2
-rw-r--r--wiretap/ascendtext.c2
-rw-r--r--wiretap/capsa.c2
-rw-r--r--wiretap/catapult_dct2000.c2
-rw-r--r--wiretap/csids.c2
-rw-r--r--wiretap/erf.c24
-rw-r--r--wiretap/file_access.c4
-rw-r--r--wiretap/i4btrace.c2
-rw-r--r--wiretap/iptrace.c4
-rw-r--r--wiretap/iseries.c2
-rw-r--r--wiretap/k12.c2
-rw-r--r--wiretap/lanalyzer.c2
-rw-r--r--wiretap/libpcap.c2
-rw-r--r--wiretap/log3gpp.c2
-rw-r--r--wiretap/logcat.c2
-rw-r--r--wiretap/logcat_text.c2
-rw-r--r--wiretap/mp2t.c2
-rw-r--r--wiretap/mpeg.c2
-rw-r--r--wiretap/netmon.c4
-rw-r--r--wiretap/netscaler.c4
-rw-r--r--wiretap/network_instruments.c4
-rw-r--r--wiretap/netxray.c6
-rw-r--r--wiretap/ngsniffer.c4
-rw-r--r--wiretap/packetlogger.c2
-rw-r--r--wiretap/pcapng.c2
-rw-r--r--wiretap/peekclassic.c2
-rw-r--r--wiretap/peektagged.c2
-rw-r--r--wiretap/pppdump.c2
-rw-r--r--wiretap/stanag4607.c2
-rw-r--r--wiretap/visual.c4
-rw-r--r--wiretap/vwr.c2
-rw-r--r--wsutil/codecs.c2
-rw-r--r--wsutil/plugins.c2
124 files changed, 437 insertions, 327 deletions
diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c
index a60fe6fb5d..e8f049818a 100644
--- a/capchild/capture_ifinfo.c
+++ b/capchild/capture_ifinfo.c
@@ -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;
diff --git a/caputils/airpcap_loader.c b/caputils/airpcap_loader.c
index 104d8300ce..8ab2ce3560 100644
--- a/caputils/airpcap_loader.c
+++ b/caputils/airpcap_loader.c
@@ -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");
diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c
index 7abe416557..364762f2da 100644
--- a/caputils/capture-pcap-util.c
+++ b/caputils/capture-pcap-util.c
@@ -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)
diff --git a/dumpcap.c b/dumpcap.c
index a8c1a78122..eba5b98404 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -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;
diff --git a/editcap.c b/editcap.c
index ebc471a551..be908dd7c0 100644
--- a/editcap.c
+++ b/editcap.c
@@ -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);
diff --git a/epan/color_filters.c b/epan/color_filters.c
index 8dfd8c2e32..08cf3da4f0 100644
--- a/epan/color_filters.c
+++ b/epan/color_filters.c
@@ -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;
diff --git a/epan/column.c b/epan/column.c
index 81f71b51cc..922f03daea 100644
--- a/epan/column.c
+++ b/epan/column.c
@@ -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;
diff --git a/epan/conversation_filter.c b/epan/conversation_filter.c
index 982b93d823..4379c70daa 100644
--- a/epan/conversation_filter.c
+++ b/epan/conversation_filter.c
@@ -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;
diff --git a/epan/crypt/dot11decrypt.c b/epan/crypt/dot11decrypt.c
index ee66810845..eda65ade5e 100644
--- a/epan/crypt/dot11decrypt.c
+++ b/epan/crypt/dot11decrypt.c
@@ -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;
diff --git a/epan/disabled_protos.c b/epan/disabled_protos.c
index d7e715fe4f..a558aaf48d 100644
--- a/epan/disabled_protos.c
+++ b/epan/disabled_protos.c
@@ -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);
diff --git a/epan/dissectors/packet-batadv.c b/epan/dissectors/packet-batadv.c
index 01483fda20..a1c4bea020 100644
--- a/epan/dissectors/packet-batadv.c
+++ b/epan/dissectors/packet-batadv.c
@@ -1121,7 +1121,7 @@ static int dissect_batadv_batman_v5(tvbuff_t *tvb, int offset, packet_info *pinf
tvbuff_t *next_tvb;
- batman_packeth = (struct batman_packet_v5 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v5));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v5);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1216,7 +1216,7 @@ static int dissect_batadv_batman_v7(tvbuff_t *tvb, int offset, packet_info *pinf
tvbuff_t *next_tvb;
- batman_packeth = (struct batman_packet_v7 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v7));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v7);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1301,7 +1301,7 @@ static int dissect_batadv_batman_v9(tvbuff_t *tvb, int offset, packet_info *pinf
tvbuff_t *next_tvb;
- batman_packeth = (struct batman_packet_v9 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v9));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v9);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1394,7 +1394,7 @@ static int dissect_batadv_batman_v10(tvbuff_t *tvb, int offset, packet_info *pin
tvbuff_t *next_tvb;
- batman_packeth = (struct batman_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v10));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v10);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1487,7 +1487,7 @@ static int dissect_batadv_batman_v11(tvbuff_t *tvb, int offset, packet_info *pin
tvbuff_t *next_tvb;
- batman_packeth = (struct batman_packet_v11 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v11));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v11);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1573,7 +1573,7 @@ static int dissect_batadv_batman_v14(tvbuff_t *tvb, int offset, packet_info *pin
tvbuff_t *next_tvb;
gint length_remaining;
- batman_packeth = (struct batman_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct batman_packet_v14));
+ batman_packeth = wmem_new(wmem_packet_scope(), struct batman_packet_v14);
type = tvb_get_guint8(tvb, offset+0);
batman_packeth->version = tvb_get_guint8(tvb, offset+1);
@@ -1712,8 +1712,7 @@ static int dissect_batadv_iv_ogm_v15(tvbuff_t *tvb, int offset,
if (version == 0 || type != BATADV_IV_OGM_V15)
return -1;
- iv_ogm_packeth = (struct iv_ogm_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct iv_ogm_packet_v15));
+ iv_ogm_packeth = wmem_new(wmem_packet_scope(), struct iv_ogm_packet_v15);
/* Set info column */
col_clear(pinfo->cinfo, COL_INFO);
@@ -1856,7 +1855,7 @@ static void dissect_batadv_bcast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tre
proto_tree *batadv_bcast_tree;
proto_item *ti;
- bcast_packeth = (struct bcast_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v6));
+ bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v6);
bcast_packeth->version = tvb_get_guint8(tvb, 1);
set_address_tvb(&bcast_packeth->orig, AT_ETHER, 6, tvb, 2);
@@ -1910,7 +1909,7 @@ static void dissect_batadv_bcast_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tr
proto_tree *batadv_bcast_tree;
proto_item *ti;
- bcast_packeth = (struct bcast_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v10));
+ bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v10);
bcast_packeth->version = tvb_get_guint8(tvb, 1);
set_address_tvb(&bcast_packeth->orig, AT_ETHER, 6, tvb, 2);
@@ -1969,7 +1968,7 @@ static void dissect_batadv_bcast_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tr
proto_tree *batadv_bcast_tree;
proto_item *ti;
- bcast_packeth = (struct bcast_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct bcast_packet_v14));
+ bcast_packeth = wmem_new(wmem_packet_scope(), struct bcast_packet_v14);
bcast_packeth->packet_type = tvb_get_guint8(tvb, 0);
bcast_packeth->version = tvb_get_guint8(tvb, 1);
@@ -2069,7 +2068,7 @@ static void dissect_batadv_icmp_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree
proto_tree *batadv_icmp_tree;
proto_item *ti;
- icmp_packeth = (struct icmp_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v6));
+ icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v6);
icmp_packeth->version = tvb_get_guint8(tvb, 1);
icmp_packeth->msg_type = tvb_get_guint8(tvb, 2);
@@ -2192,7 +2191,7 @@ static void dissect_batadv_icmp_v7(tvbuff_t *tvb, packet_info *pinfo, proto_tree
gint length_remaining;
int offset = 0;
- icmp_packeth = (struct icmp_packet_v7 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v7));
+ icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v7);
icmp_packeth->version = tvb_get_guint8(tvb, 1);
icmp_packeth->msg_type = tvb_get_guint8(tvb, 2);
@@ -2272,7 +2271,7 @@ static void dissect_batadv_icmp_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tre
gint length_remaining;
int offset = 0;
- icmp_packeth = (struct icmp_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct icmp_packet_v14));
+ icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v14);
icmp_packeth->version = tvb_get_guint8(tvb, 1);
icmp_packeth->ttl = tvb_get_guint8(tvb, 2);
@@ -2358,8 +2357,7 @@ static void dissect_batadv_icmp_tp_v15(tvbuff_t *tvb, packet_info *pinfo,
guint32 msg_type;
int offset = 0;
- icmp_packeth = (struct icmp_tp_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct icmp_tp_packet_v15));
+ icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_tp_packet_v15);
/* Set info column */
col_clear(pinfo->cinfo, COL_INFO);
@@ -2462,8 +2460,7 @@ static void dissect_batadv_icmp_simple_v15(tvbuff_t *tvb, packet_info *pinfo,
int offset = 0;
guint32 seqno;
- icmp_packeth = (struct icmp_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct icmp_packet_v15));
+ icmp_packeth = wmem_new(wmem_packet_scope(), struct icmp_packet_v15);
/* Set info column */
col_clear(pinfo->cinfo, COL_INFO);
@@ -2607,7 +2604,7 @@ static void dissect_batadv_unicast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_t
proto_tree *batadv_unicast_tree;
proto_item *ti;
- unicast_packeth = (struct unicast_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_packet_v6));
+ unicast_packeth = wmem_new(wmem_packet_scope(), struct unicast_packet_v6);
unicast_packeth->version = tvb_get_guint8(tvb, 1);
set_address_tvb(&unicast_packeth->dest, AT_ETHER, 6, tvb, 2);
@@ -2663,7 +2660,7 @@ static void dissect_batadv_unicast_v14(tvbuff_t *tvb, packet_info *pinfo, proto_
proto_tree *batadv_unicast_tree;
proto_item *ti;
- unicast_packeth = (struct unicast_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_packet_v14));
+ unicast_packeth = wmem_new(wmem_packet_scope(), struct unicast_packet_v14);
unicast_packeth->packet_type = tvb_get_guint8(tvb, 0);
unicast_packeth->version = tvb_get_guint8(tvb, 1);
@@ -2747,7 +2744,7 @@ static void dissect_batadv_unicast_4addr_v14(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *batadv_unicast_4addr_tree;
proto_item *ti;
- unicast_4addr_packeth = (struct unicast_4addr_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_4addr_packet_v14));
+ unicast_4addr_packeth = wmem_new(wmem_packet_scope(), struct unicast_4addr_packet_v14);
unicast_4addr_packeth->packet_type = tvb_get_guint8(tvb, 0);
unicast_4addr_packeth->version = tvb_get_guint8(tvb, 1);
@@ -2855,7 +2852,7 @@ static void dissect_batadv_unicast_frag_v12(tvbuff_t *tvb, packet_info *pinfo, p
int head = 0;
gint length_remaining;
- unicast_frag_packeth = (struct unicast_frag_packet_v12 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_frag_packet_v12));
+ unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v12);
unicast_frag_packeth->version = tvb_get_guint8(tvb, 1);
set_address_tvb(&unicast_frag_packeth->dest, AT_ETHER, 6, tvb, 2);
@@ -2944,7 +2941,7 @@ static void dissect_batadv_unicast_frag_v14(tvbuff_t *tvb, packet_info *pinfo, p
int head = 0;
gint length_remaining;
- unicast_frag_packeth = (struct unicast_frag_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct unicast_frag_packet_v14));
+ unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v14);
unicast_frag_packeth->version = tvb_get_guint8(tvb, 1);
unicast_frag_packeth->ttl = tvb_get_guint8(tvb, 2);
@@ -3042,8 +3039,7 @@ static void dissect_batadv_unicast_frag_v15(tvbuff_t *tvb, packet_info *pinfo,
int frag_no = 0;
gint length_remaining;
- unicast_frag_packeth = (struct unicast_frag_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct unicast_frag_packet_v15));
+ unicast_frag_packeth = wmem_new(wmem_packet_scope(), struct unicast_frag_packet_v15);
save_fragmented = pinfo->fragmented;
pinfo->fragmented = TRUE;
@@ -3191,7 +3187,7 @@ static void dissect_batadv_vis_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree
gint length_remaining;
int offset = 0, i;
- vis_packeth = (struct vis_packet_v6 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v6));
+ vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v6);
vis_packeth->version = tvb_get_guint8(tvb, 1);
vis_packeth->vis_type = tvb_get_guint8(tvb, 2);
@@ -3307,7 +3303,7 @@ static void dissect_batadv_vis_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree
gint length_remaining;
int offset = 0, i;
- vis_packeth = (struct vis_packet_v10 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v10));
+ vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v10);
vis_packeth->version = tvb_get_guint8(tvb, 1);
vis_packeth->vis_type = tvb_get_guint8(tvb, 2);
@@ -3399,7 +3395,7 @@ static void dissect_batadv_vis_v14(tvbuff_t *tvb, packet_info *pinfo, proto_tree
gint length_remaining;
int offset = 0, i;
- vis_packeth = (struct vis_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct vis_packet_v14));
+ vis_packeth = wmem_new(wmem_packet_scope(), struct vis_packet_v14);
vis_packeth->version = tvb_get_guint8(tvb, 1);
vis_packeth->ttl = tvb_get_guint8(tvb, 2);
@@ -3543,7 +3539,7 @@ static void dissect_batadv_tt_query_v14(tvbuff_t *tvb, packet_info *pinfo, proto
int offset = 0, i;
int tt_type;
- tt_query_packeth = (struct tt_query_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct tt_query_packet_v14));
+ tt_query_packeth = wmem_new(wmem_packet_scope(), struct tt_query_packet_v14);
tt_query_packeth->version = tvb_get_guint8(tvb, 1);
tt_query_packeth->ttl = tvb_get_guint8(tvb, 2);
@@ -3688,7 +3684,7 @@ static void dissect_batadv_roam_adv_v14(tvbuff_t *tvb, packet_info *pinfo, proto
gint length_remaining;
int offset = 0;
- roam_adv_packeth = (struct roam_adv_packet_v14 *)wmem_alloc(wmem_packet_scope(), sizeof(struct roam_adv_packet_v14));
+ roam_adv_packeth = wmem_new(wmem_packet_scope(), struct roam_adv_packet_v14);
roam_adv_packeth->version = tvb_get_guint8(tvb, 1);
roam_adv_packeth->ttl = tvb_get_guint8(tvb, 2);
@@ -3776,8 +3772,7 @@ static void dissect_batadv_coded_v15(tvbuff_t *tvb, packet_info *pinfo,
gint length_remaining;
int offset = 0;
- coded_packeth = (struct coded_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct coded_packet_v15));
+ coded_packeth = wmem_new(wmem_packet_scope(), struct coded_packet_v15);
/* Set tree info */
ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin,
@@ -3911,8 +3906,7 @@ static void dissect_batadv_elp_v15(tvbuff_t *tvb, packet_info *pinfo,
gint length_remaining;
int offset = 0;
- elp_packeth = (struct elp_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct elp_packet_v15));
+ elp_packeth = wmem_new(wmem_packet_scope(), struct elp_packet_v15);
/* Set tree info */
ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin,
@@ -4009,8 +4003,7 @@ static int dissect_batadv_ogm2_v15(tvbuff_t *tvb, int offset,
if (version == 0 || type != BATADV_OGM2_V15)
return -1;
- ogm2_packeth = (struct ogm2_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct ogm2_packet_v15));
+ ogm2_packeth = wmem_new(wmem_packet_scope(), struct ogm2_packet_v15);
/* Set tree info */
ogm2_packeth->tvlv_len = tvb_get_ntohs(tvb, 16);
@@ -4120,8 +4113,7 @@ static void dissect_batadv_unicast_tvlv_v15(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *batadv_unicast_tvlv_tree;
proto_item *ti;
- unicast_tvlv_packeth = (struct unicast_tvlv_packet_v15 *)wmem_alloc(wmem_packet_scope(),
- sizeof(struct unicast_tvlv_packet_v15));
+ unicast_tvlv_packeth = wmem_new(wmem_packet_scope(), struct unicast_tvlv_packet_v15);
/* Set info column */
col_clear(pinfo->cinfo, COL_INFO);
diff --git a/epan/dissectors/packet-btmesh.c b/epan/dissectors/packet-btmesh.c
index f1562a2ed3..124faf86f8 100644
--- a/epan/dissectors/packet-btmesh.c
+++ b/epan/dissectors/packet-btmesh.c
@@ -3630,10 +3630,10 @@ uat_btmesh_record_update_cb(void *r, char **err _U_)
g_free(rec->network_key);
rec->network_key_length = compute_ascii_key(&rec->network_key, rec->network_key_string);
g_free(rec->encryptionkey);
- rec->encryptionkey = (guint8 *)g_malloc(16 * sizeof(guint8));
+ rec->encryptionkey = g_new(guint8, 16);
memset(rec->encryptionkey, 0, 16 * sizeof(guint8));
g_free(rec->privacykey);
- rec->privacykey = (guint8 *)g_malloc(16 * sizeof(guint8));
+ rec->privacykey = g_new(guint8, 16);
if (create_master_security_keys(rec)) {
rec->valid++;
}
diff --git a/epan/dissectors/packet-dbus.c b/epan/dissectors/packet-dbus.c
index 4fd951c90f..a6a3d33fa7 100644
--- a/epan/dissectors/packet-dbus.c
+++ b/epan/dissectors/packet-dbus.c
@@ -698,8 +698,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) {
is_single_complete_type = TRUE;
} else if (array_len <= DBUS_MAX_ARRAY_LEN) {
int end_offset = ptvcursor_current_offset(packet->cursor) + array_len;
- dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc(
- wmem_packet_scope(), sizeof(dbus_type_reader_t));
+ dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t);
*child = (dbus_type_reader_t){
.packet = reader->packet,
.signature = reader->signature,
@@ -722,8 +721,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) {
is_single_complete_type = FALSE;
ptvcursor_add_with_subtree(packet->cursor, hf != -1 ? hf : hf_dbus_type_struct,
SUBTREE_UNDEFINED_LENGTH, ENC_NA, ett != -1 ? ett : ett_dbus_type_struct);
- dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc(
- wmem_packet_scope(), sizeof(dbus_type_reader_t));
+ dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t);
*child = (dbus_type_reader_t){
.packet = reader->packet,
.signature = reader->signature,
@@ -742,8 +740,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) {
const char *variant_signature = add_dbus_string(packet, hf_dbus_type_variant_signature, 1);
value->string = variant_signature;
if (variant_signature && is_dbus_signature_valid(variant_signature)) {
- dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc(
- wmem_packet_scope(), sizeof(dbus_type_reader_t));
+ dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t);
*child = (dbus_type_reader_t){
.packet = reader->packet,
.signature = variant_signature,
@@ -770,8 +767,7 @@ reader_next(dbus_type_reader_t *reader, int hf, int ett, dbus_val_t *value) {
proto_item *dict_entry = ptvcursor_add_with_subtree(packet->cursor,
hf != -1 ? hf : hf_dbus_type_dict_entry,
SUBTREE_UNDEFINED_LENGTH, ENC_NA, ett != -1 ? ett : ett_dbus_type_dict_entry);
- dbus_type_reader_t *child = (dbus_type_reader_t *)wmem_alloc(
- wmem_packet_scope(), sizeof(dbus_type_reader_t));
+ dbus_type_reader_t *child = wmem_new(wmem_packet_scope(), dbus_type_reader_t);
*child = (dbus_type_reader_t){
.packet = reader->packet,
.signature = reader->signature,
diff --git a/epan/dissectors/packet-dcerpc.c b/epan/dissectors/packet-dcerpc.c
index a57b2849eb..a37c51b69c 100644
--- a/epan/dissectors/packet-dcerpc.c
+++ b/epan/dissectors/packet-dcerpc.c
@@ -778,7 +778,7 @@ dcerpc_add_conv_to_bind_table(decode_dcerpc_bind_values_t *binding)
0);
}
- bind_value = (dcerpc_bind_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_value));
+ bind_value = wmem_new(wmem_file_scope(), dcerpc_bind_value);
bind_value->uuid = binding->uuid;
bind_value->ver = binding->ver;
/* For now, assume all DCE/RPC we pick from "decode as" is using
@@ -787,7 +787,7 @@ dcerpc_add_conv_to_bind_table(decode_dcerpc_bind_values_t *binding)
*/
bind_value->transport = uuid_data_repr_proto;
- key = (dcerpc_bind_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_key));
+ key = wmem_new(wmem_file_scope(), dcerpc_bind_key);
key->conv = conv;
key->ctx_id = binding->ctx_id;
key->transport_salt = binding->transport_salt;
@@ -1195,7 +1195,7 @@ void register_dcerpc_auth_subdissector(guint8 auth_level, guint8 auth_type,
if (get_auth_subdissector_fns(auth_level, auth_type))
return;
- d = (dcerpc_auth_subdissector *)g_malloc(sizeof(dcerpc_auth_subdissector));
+ d = g_new(dcerpc_auth_subdissector, 1);
d->auth_level = auth_level;
d->auth_type = auth_type;
@@ -3172,7 +3172,7 @@ add_pointer_to_list(packet_info *pinfo, proto_tree *tree, proto_item *item,
}
}
- npd = (ndr_pointer_data_t *)g_malloc(sizeof(ndr_pointer_data_t));
+ npd = g_new(ndr_pointer_data_t, 1);
npd->id = id;
npd->tree = tree;
npd->item = item;
@@ -3803,7 +3803,7 @@ static dcerpc_auth_context *find_or_create_dcerpc_auth_context(packet_info *pinf
goto return_value;
}
- auth_value = (dcerpc_auth_context *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_auth_context));
+ auth_value = wmem_new(wmem_file_scope(), dcerpc_auth_context);
if (auth_value == NULL) {
return NULL;
}
@@ -4155,12 +4155,12 @@ dissect_dcerpc_cn_bind(tvbuff_t *tvb, gint offset, packet_info *pinfo,
dcerpc_bind_key *key;
dcerpc_bind_value *value;
- key = (dcerpc_bind_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_key));
+ key = wmem_new(wmem_file_scope(), dcerpc_bind_key);
key->conv = conv;
key->ctx_id = ctx_id;
key->transport_salt = dcerpc_get_transport_salt(pinfo);
- value = (dcerpc_bind_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_bind_value));
+ value = wmem_new(wmem_file_scope(), dcerpc_bind_value);
value->uuid = if_id;
value->ver = if_ver;
value->transport = trans_id;
@@ -4636,7 +4636,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo,
call_key.call_id = hdr->call_id;
call_key.transport_salt = dcerpc_get_transport_salt(pinfo);
if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_cn_calls, &call_key))) {
- new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
+ new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key);
*new_matched_key = matched_key;
wmem_map_insert(dcerpc_matched, new_matched_key, call_value);
value = call_value;
@@ -4650,7 +4650,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo,
the call to both the call table and the
matched table
*/
- call_key = (dcerpc_cn_call_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_cn_call_key));
+ call_key = wmem_new(wmem_file_scope(), dcerpc_cn_call_key);
call_key->conv = conv;
call_key->call_id = hdr->call_id;
call_key->transport_salt = dcerpc_get_transport_salt(pinfo);
@@ -4661,7 +4661,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo,
wmem_map_remove(dcerpc_cn_calls, call_key);
}
- call_value = (dcerpc_call_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_call_value));
+ call_value = wmem_new(wmem_file_scope(), dcerpc_call_value);
call_value->uuid = bind_value->uuid;
call_value->ver = bind_value->ver;
call_value->object_uuid = obj_id;
@@ -4680,7 +4680,7 @@ dissect_dcerpc_cn_rqst(tvbuff_t *tvb, gint offset, packet_info *pinfo,
wmem_map_insert(dcerpc_cn_calls, call_key, call_value);
- new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
+ new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key);
*new_matched_key = matched_key;
wmem_map_insert(dcerpc_matched, new_matched_key, call_value);
value = call_value;
@@ -4796,7 +4796,7 @@ dissect_dcerpc_cn_resp(tvbuff_t *tvb, gint offset, packet_info *pinfo,
/* extra sanity check, only match them if the reply
came after the request */
if (call_value->req_frame<pinfo->num) {
- new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
+ new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key);
*new_matched_key = matched_key;
wmem_map_insert(dcerpc_matched, new_matched_key, call_value);
value = call_value;
@@ -4960,7 +4960,7 @@ dissect_dcerpc_cn_fault(tvbuff_t *tvb, gint offset, packet_info *pinfo,
call_key.transport_salt = dcerpc_get_transport_salt(pinfo);
if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_cn_calls, &call_key))) {
- new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
+ new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key);
*new_matched_key = matched_key;
wmem_map_insert(dcerpc_matched, new_matched_key, call_value);
@@ -6207,12 +6207,12 @@ dissect_dcerpc_dg_rqst(tvbuff_t *tvb, int offset, packet_info *pinfo,
dcerpc_call_value *call_value;
dcerpc_dg_call_key *call_key;
- call_key = (dcerpc_dg_call_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_dg_call_key));
+ call_key = wmem_new(wmem_file_scope(), dcerpc_dg_call_key);
call_key->conv = conv;
call_key->seqnum = hdr->seqnum;
call_key->act_id = hdr->act_id;
- call_value = (dcerpc_call_value *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_call_value));
+ call_value = wmem_new(wmem_file_scope(), dcerpc_call_value);
call_value->uuid = hdr->if_id;
call_value->ver = hdr->if_ver;
call_value->object_uuid = hdr->obj_id;
@@ -6291,7 +6291,7 @@ dissect_dcerpc_dg_resp(tvbuff_t *tvb, int offset, packet_info *pinfo,
call_key.act_id = hdr->act_id;
if ((call_value = (dcerpc_call_value *)wmem_map_lookup(dcerpc_dg_calls, &call_key))) {
- new_matched_key = (dcerpc_matched_key *)wmem_alloc(wmem_file_scope(), sizeof (dcerpc_matched_key));
+ new_matched_key = wmem_new(wmem_file_scope(), dcerpc_matched_key);
new_matched_key->frame = pinfo->num;
new_matched_key->call_id = hdr->seqnum;
wmem_map_insert(dcerpc_matched, new_matched_key, call_value);
diff --git a/epan/dissectors/packet-dpaux.c b/epan/dissectors/packet-dpaux.c
index 53cce1539d..4d4e1c0d0e 100644
--- a/epan/dissectors/packet-dpaux.c
+++ b/epan/dissectors/packet-dpaux.c
@@ -179,8 +179,7 @@ dissect_dpaux_from_source(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
conversation = conversation_new(pinfo->num, &pinfo->src, &pinfo->dst,
ENDPOINT_NONE, pinfo->srcport, pinfo->destport, 0);
- transaction = (struct dpaux_transaction*)wmem_alloc(wmem_file_scope(),
- sizeof(struct dpaux_transaction));
+ transaction = wmem_new(wmem_file_scope(), struct dpaux_transaction);
transaction->is_native = type;
transaction->addr = addr;
diff --git a/epan/dissectors/packet-exported_pdu.c b/epan/dissectors/packet-exported_pdu.c
index 540fae45fa..490e4b3e7e 100644
--- a/epan/dissectors/packet-exported_pdu.c
+++ b/epan/dissectors/packet-exported_pdu.c
@@ -266,7 +266,7 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
break;
case EXP_PDU_TAG_SS7_OPC:
proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_opc, tvb, offset, 4, ENC_BIG_ENDIAN);
- mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
+ mtp3_addr = wmem_new0(pinfo->pool, mtp3_addr_pc_t);
mtp3_addr->pc = tvb_get_ntohl(tvb, offset);
mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4);
mtp3_addr->ni = tvb_get_guint8(tvb, offset+6);
@@ -274,7 +274,7 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
break;
case EXP_PDU_TAG_SS7_DPC:
proto_tree_add_item(tag_tree, hf_exported_pdu_ss7_dpc, tvb, offset, 4, ENC_BIG_ENDIAN);
- mtp3_addr = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
+ mtp3_addr = wmem_new0(pinfo->pool, mtp3_addr_pc_t);
mtp3_addr->pc = tvb_get_ntohl(tvb, offset);
mtp3_addr->type = (Standard_Type)tvb_get_ntohs(tvb, offset+4);
mtp3_addr->ni = tvb_get_guint8(tvb, offset+6);
diff --git a/epan/dissectors/packet-fpp.c b/epan/dissectors/packet-fpp.c
index dd9514520d..25a0443551 100644
--- a/epan/dissectors/packet-fpp.c
+++ b/epan/dissectors/packet-fpp.c
@@ -368,7 +368,7 @@ dissect_preemption(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32
if (!PINFO_FD_VISITED(pinfo)) {
// Fist delete previous conversation
drop_conversation(conv);
- ctx = (struct _fpp_ctx_t *)wmem_alloc(wmem_file_scope(), sizeof(struct _fpp_ctx_t));
+ ctx = wmem_new(wmem_file_scope(), struct _fpp_ctx_t);
init_fpp_ctx(ctx, get_cont_by_start(smd2));
ctx->size = frag_size;
conversation_add_proto_data(conv, proto_fpp, ctx);
diff --git a/epan/dissectors/packet-giop.c b/epan/dissectors/packet-giop.c
index 2f211a7d90..0226f97249 100644
--- a/epan/dissectors/packet-giop.c
+++ b/epan/dissectors/packet-giop.c
@@ -1337,12 +1337,12 @@ void register_giop_user_module(giop_sub_dissector_t *sub, const gchar *name, con
ws_debug_printf("giop:register_module: Module sub dissector name is %s \n", name);
#endif
- new_module_key = (struct giop_module_key *)wmem_alloc(wmem_epan_scope(), sizeof(struct giop_module_key));
+ new_module_key = wmem_new(wmem_epan_scope(), struct giop_module_key);
new_module_key->module = module; /* save Module or interface name from IDL */
- module_val = (struct giop_module_val *)wmem_alloc(wmem_epan_scope(), sizeof(struct giop_module_val));
+ module_val = wmem_new(wmem_epan_scope(), struct giop_module_val);
- module_val->subh = (giop_sub_handle_t *)wmem_alloc(wmem_epan_scope(), sizeof (giop_sub_handle_t)); /* init subh */
+ module_val->subh = wmem_new(wmem_epan_scope(), giop_sub_handle_t); /* init subh */
module_val->subh->sub_name = name; /* save dissector name */
module_val->subh->sub_fn = sub; /* save subdissector*/
@@ -1615,7 +1615,7 @@ void register_giop_user(giop_sub_dissector_t *sub, const gchar *name, int sub_pr
giop_sub_handle_t *subh;
- subh = (giop_sub_handle_t *)wmem_alloc(wmem_epan_scope(), sizeof (giop_sub_handle_t));
+ subh = wmem_new(wmem_epan_scope(), giop_sub_handle_t);
subh->sub_name = name;
subh->sub_fn = sub;
diff --git a/epan/dissectors/packet-hpfeeds.c b/epan/dissectors/packet-hpfeeds.c
index 66ff034dbb..a5abc14f56 100644
--- a/epan/dissectors/packet-hpfeeds.c
+++ b/epan/dissectors/packet-hpfeeds.c
@@ -230,7 +230,7 @@ static tap_packet_status hpfeeds_stats_tree_packet(stats_tree* st _U_, packet_in
}
if (cur == NULL) {
- ch_node = (struct channel_node*)wmem_alloc0(wmem_file_scope(), sizeof(struct channel_node));
+ ch_node = wmem_new0(wmem_file_scope(), struct channel_node);
ch_node->channel = wmem_strdup(wmem_file_scope(), pi->channel);
ch_node->st_node_channel_payload = stats_tree_create_node(st, ch_node->channel,
st_node_channels_payload, STAT_DT_INT, FALSE);
diff --git a/epan/dissectors/packet-idn.c b/epan/dissectors/packet-idn.c
index 0458f8d595..6330a6ded1 100644
--- a/epan/dissectors/packet-idn.c
+++ b/epan/dissectors/packet-idn.c
@@ -937,7 +937,7 @@ static int dissect_idn_message_header(tvbuff_t *tvb, int offset, proto_tree *idn
static int dissect_idn_message(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *idn_tree) {
int scm;
configuration_info *config = NULL;
- message_info *minfo = (message_info *)wmem_alloc(wmem_file_scope(), sizeof(message_info));
+ message_info *minfo = wmem_new(wmem_file_scope(), message_info);
offset = dissect_idn_message_header(tvb, offset, idn_tree, minfo);
determine_message_type(pinfo, minfo);
@@ -945,7 +945,7 @@ static int dissect_idn_message(tvbuff_t *tvb, packet_info *pinfo, int offset, pr
return offset;
if(minfo->has_config_header && minfo->chunk_type != IDNCT_LP_FRAME_SF) {
- config = (configuration_info *)wmem_alloc0(wmem_file_scope(), sizeof(configuration_info));
+ config = wmem_new0(wmem_file_scope(), configuration_info);
offset = dissect_idn_channel_configuration(tvb, pinfo, offset, idn_tree, minfo, config);
}else if(minfo->chunk_type != IDNCT_VOID) {
config = get_configuration_info(pinfo, minfo->channel_id);
diff --git a/epan/dissectors/packet-ieee802a.c b/epan/dissectors/packet-ieee802a.c
index 4e68ddcca6..0d78073051 100644
--- a/epan/dissectors/packet-ieee802a.c
+++ b/epan/dissectors/packet-ieee802a.c
@@ -46,7 +46,7 @@ ieee802a_add_oui(guint32 oui, const char *table_name, const char *table_ui_name,
{
oui_info_t *new_info;
- new_info = (oui_info_t *)g_malloc(sizeof (oui_info_t));
+ new_info = g_new(oui_info_t, 1);
new_info->table = register_dissector_table(table_name,
table_ui_name, proto, FT_UINT16, BASE_HEX);
new_info->field_info = hf_item;
diff --git a/epan/dissectors/packet-imf.c b/epan/dissectors/packet-imf.c
index 18c1352d04..1ad5c83d70 100644
--- a/epan/dissectors/packet-imf.c
+++ b/epan/dissectors/packet-imf.c
@@ -973,11 +973,11 @@ header_fields_post_update_cb (void)
if (num_header_fields) {
custom_field_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_imf_field);
- dynamic_hf = (hf_register_info *)g_malloc0 (sizeof (hf_register_info) * num_header_fields);
+ dynamic_hf = g_new0(hf_register_info, num_header_fields);
dynamic_hf_size = num_header_fields;
for (guint i = 0; i < dynamic_hf_size; i++) {
- hf_id = (gint *)g_malloc (sizeof (gint));
+ hf_id = g_new(gint, 1);
*hf_id = -1;
header_name = g_strdup (header_fields[i].header_name);
@@ -991,7 +991,7 @@ header_fields_post_update_cb (void)
dynamic_hf[i].hfinfo.blurb = g_strdup (header_fields[i].description);
HFILL_INIT(dynamic_hf[i]);
- imffield = (struct imf_field *)g_malloc (sizeof (struct imf_field));
+ imffield = g_new(struct imf_field, 1);
imffield->hf_id = hf_id;
imffield->name = g_ascii_strdown(header_name, -1);
switch (header_fields[i].header_format) {
diff --git a/epan/dissectors/packet-infiniband.c b/epan/dissectors/packet-infiniband.c
index d2d8809703..ad58ed6235 100644
--- a/epan/dissectors/packet-infiniband.c
+++ b/epan/dissectors/packet-infiniband.c
@@ -3325,10 +3325,10 @@ static void save_conversation_info(packet_info *pinfo, guint8 *local_gid, guint8
connection_context *connection;
conversation_infiniband_data *proto_data;
conversation_t *conv;
- guint64 *hash_key = (guint64 *)g_malloc(sizeof(guint64));
+ guint64 *hash_key = g_new(guint64, 1);
/* create a new connection context and store it in the hash table */
- connection = (connection_context *)g_malloc(sizeof(connection_context));
+ connection = g_new(connection_context, 1);
if (pinfo->dst.type == AT_IPv4) {
memcpy(&(connection->req_gid), local_gid, 4);
diff --git a/epan/dissectors/packet-ipmi.c b/epan/dissectors/packet-ipmi.c
index 7fc4e13058..91ab7655b8 100644
--- a/epan/dissectors/packet-ipmi.c
+++ b/epan/dissectors/packet-ipmi.c
@@ -1122,7 +1122,7 @@ ipmi_register_netfn_cmdtab(guint32 netfn, guint oem_selector,
return;
}
- inh = (struct ipmi_netfn_handler *)wmem_alloc(wmem_epan_scope(), sizeof(struct ipmi_netfn_handler));
+ inh = wmem_new(wmem_epan_scope(), struct ipmi_netfn_handler);
inh->desc = desc;
inh->oem_selector = oem_selector;
inh->sig = sig;
diff --git a/epan/dissectors/packet-ipsec.c b/epan/dissectors/packet-ipsec.c
index 2b736ddcad..63acc3c1f6 100644
--- a/epan/dissectors/packet-ipsec.c
+++ b/epan/dissectors/packet-ipsec.c
@@ -404,7 +404,7 @@ void esp_sa_record_add_from_dissector(guint8 protocol, const gchar *srcIP, const
{
uat_esp_sa_record_t* record = NULL;
if (extra_esp_sa_records.num_records == 0) {
- extra_esp_sa_records.records = (uat_esp_sa_record_t *)g_malloc(sizeof(uat_esp_sa_record_t)*MAX_EXTRA_SA_RECORDS);
+ extra_esp_sa_records.records = g_new(uat_esp_sa_record_t, MAX_EXTRA_SA_RECORDS);
}
if (extra_esp_sa_records.num_records < MAX_EXTRA_SA_RECORDS) {
record = &extra_esp_sa_records.records[extra_esp_sa_records.num_records++];
diff --git a/epan/dissectors/packet-k12.c b/epan/dissectors/packet-k12.c
index cf43175b40..dd08af5423 100644
--- a/epan/dissectors/packet-k12.c
+++ b/epan/dissectors/packet-k12.c
@@ -301,7 +301,7 @@ k12_update_cb(void* r, char** err)
g_free(h->handles);
/* Allocate extra space for NULL marker */
- h->handles = (dissector_handle_t *)g_malloc0(sizeof(dissector_handle_t)*(num_protos+1));
+ h->handles = g_new0(dissector_handle_t, (num_protos+1));
for (i = 0; i < num_protos; i++) {
if ( ! (h->handles[i] = find_dissector(protos[i])) ) {
diff --git a/epan/dissectors/packet-mac-lte-framed.c b/epan/dissectors/packet-mac-lte-framed.c
index b901add561..0a805513af 100644
--- a/epan/dissectors/packet-mac-lte-framed.c
+++ b/epan/dissectors/packet-mac-lte-framed.c
@@ -51,7 +51,7 @@ static int dissect_mac_lte_framed(tvbuff_t *tvb, packet_info *pinfo,
p_mac_lte_info = (struct mac_lte_info*)p_get_proto_data(wmem_file_scope(), pinfo, proto_mac_lte, 0);
if (p_mac_lte_info == NULL) {
/* Allocate new info struct for this frame */
- p_mac_lte_info = (struct mac_lte_info*)wmem_alloc0(wmem_file_scope(), sizeof(struct mac_lte_info));
+ p_mac_lte_info = wmem_new0(wmem_file_scope(), struct mac_lte_info);
infoAlreadySet = FALSE;
}
else {
diff --git a/epan/dissectors/packet-mswsp.c b/epan/dissectors/packet-mswsp.c
index 09d412bf06..37ad06c2b2 100644
--- a/epan/dissectors/packet-mswsp.c
+++ b/epan/dissectors/packet-mswsp.c
@@ -755,7 +755,7 @@ static struct message_data *find_or_create_message_data(struct mswsp_ct *conv_da
result = g_slist_find_custom(conv_data->GSL_message_data,
&to_find, (GCompareFunc)msg_data_find);
if (!result) {
- msg_data = (struct message_data *)wmem_alloc(wmem_file_scope(), sizeof(struct message_data));
+ msg_data = wmem_new(wmem_file_scope(), struct message_data);
*msg_data = to_find;
conv_data->GSL_message_data = g_slist_prepend(conv_data->GSL_message_data, msg_data);
} else {
diff --git a/epan/dissectors/packet-mtp3.c b/epan/dissectors/packet-mtp3.c
index 559e95a8eb..a04b017047 100644
--- a/epan/dissectors/packet-mtp3.c
+++ b/epan/dissectors/packet-mtp3.c
@@ -781,8 +781,8 @@ dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
/* create display subtree for the protocol */
mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
- mtp3_addr_opc = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
- mtp3_addr_dpc = (mtp3_addr_pc_t *)wmem_alloc0(pinfo->pool, sizeof(mtp3_addr_pc_t));
+ mtp3_addr_opc = wmem_new0(pinfo->pool, mtp3_addr_pc_t);
+ mtp3_addr_dpc = wmem_new0(pinfo->pool, mtp3_addr_pc_t);
/* Dissect the packet (even if !tree so can call sub-dissectors and update
* the source and destination address columns) */
diff --git a/epan/dissectors/packet-nano.c b/epan/dissectors/packet-nano.c
index b0cbbacd66..fe687835f9 100644
--- a/epan/dissectors/packet-nano.c
+++ b/epan/dissectors/packet-nano.c
@@ -743,7 +743,7 @@ static int dissect_nano_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
session_state = (struct nano_session_state *)conversation_get_proto_data(conversation, proto_nano);
if (!session_state) {
// create new session state
- session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state));
+ session_state = wmem_new0(wmem_file_scope(), struct nano_session_state);
session_state->client_packet_type = NANO_PACKET_TYPE_INVALID;
session_state->server_port = pinfo->match_uint;
conversation_add_proto_data(conversation, proto_nano, session_state);
@@ -753,7 +753,7 @@ static int dissect_nano_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
packet_session_state = (struct nano_session_state *)p_get_proto_data(wmem_file_scope(), pinfo, proto_nano, 0);
if (!packet_session_state) {
// this packet does not have a stored session state, get it from the conversation
- packet_session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state));
+ packet_session_state = wmem_new0(wmem_file_scope(), struct nano_session_state);
memcpy(packet_session_state, session_state, sizeof(struct nano_session_state));
p_add_proto_data(wmem_file_scope(), pinfo, proto_nano, 0, packet_session_state);
} else {
@@ -827,7 +827,7 @@ static gboolean dissect_nano_heur_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_t
session_state = (struct nano_session_state *)conversation_get_proto_data(conversation, proto_nano);
if (!session_state) {
// create new session state
- session_state = (struct nano_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct nano_session_state));
+ session_state = wmem_new0(wmem_file_scope(), struct nano_session_state);
session_state->client_packet_type = NANO_PACKET_TYPE_INVALID;
session_state->server_port = pinfo->destport;
conversation_add_proto_data(conversation, proto_nano, session_state);
diff --git a/epan/dissectors/packet-nvme-tcp.c b/epan/dissectors/packet-nvme-tcp.c
index 8bd868bd65..40180eb9c5 100644
--- a/epan/dissectors/packet-nvme-tcp.c
+++ b/epan/dissectors/packet-nvme-tcp.c
@@ -1118,8 +1118,7 @@ dissect_nvme_tcp_pdu(tvbuff_t *tvb,
conversation_get_proto_data(conversation, proto_nvme_tcp);
if (!q_ctx) {
- q_ctx = (struct nvme_tcp_q_ctx *) wmem_alloc0(wmem_file_scope(),
- sizeof(struct nvme_tcp_q_ctx));
+ q_ctx = wmem_new0(wmem_file_scope(), struct nvme_tcp_q_ctx);
q_ctx->n_q_ctx.pending_cmds = wmem_tree_new(wmem_file_scope());
q_ctx->n_q_ctx.done_cmds = wmem_tree_new(wmem_file_scope());
q_ctx->n_q_ctx.data_requests = wmem_tree_new(wmem_file_scope());
diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c
index b745619407..6a88193582 100644
--- a/epan/dissectors/packet-radius.c
+++ b/epan/dissectors/packet-radius.c
@@ -1677,7 +1677,7 @@ dissect_attribute_value_pairs(proto_tree *tree, packet_info *pinfo, tvbuff_t *tv
if (avp_vsa_flags & 0x80) {
if (!vsa_buffer) {
- vsa_buffer = (radius_vsa_buffer *)g_malloc(sizeof(radius_vsa_buffer));
+ vsa_buffer = g_new(radius_vsa_buffer, 1);
vsa_buffer->key.vendor_id = vendor_id;
vsa_buffer->key.vsa_type = avp_vsa_type;
vsa_buffer->len = avp_vsa_len;
@@ -2482,7 +2482,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a
vendor = (radius_vendor_info_t *)g_hash_table_lookup(dict->vendors_by_id, GUINT_TO_POINTER(vendor_id));
if (!vendor) {
- vendor = (radius_vendor_info_t *)g_malloc(sizeof(radius_vendor_info_t));
+ vendor = g_new(radius_vendor_info_t, 1);
vendor->name = g_strdup_printf("%s-%u",
enterprises_lookup(vendor_id, "Unknown"),
@@ -2508,7 +2508,7 @@ radius_register_avp_dissector(guint32 vendor_id, guint32 _attribute_id, radius_a
}
if (!dictionary_entry) {
- dictionary_entry = (radius_attr_info_t *)g_malloc(sizeof(radius_attr_info_t));
+ dictionary_entry = g_new(radius_attr_info_t, 1);
dictionary_entry->name = g_strdup_printf("Unknown-Attribute-%u", attribute_id.value);
dictionary_entry->code = attribute_id;
@@ -2849,7 +2849,7 @@ proto_register_radius(void)
radius_tap = register_tap("radius");
proto_register_prefix("radius", register_radius_fields);
- dict = (radius_dictionary_t *)g_malloc(sizeof(radius_dictionary_t));
+ dict = g_new(radius_dictionary_t, 1);
/*
* IDs map to names and vice versa. The attribute and vendor is stored
* only once, but referenced by both name and ID mappings.
diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c
index 79ec7bd033..5a9a22544e 100644
--- a/epan/dissectors/packet-rpc.c
+++ b/epan/dissectors/packet-rpc.c
@@ -521,7 +521,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers,
size_t versidx;
const vsff *proc;
- value = (rpc_prog_info_value *) g_malloc(sizeof(rpc_prog_info_value));
+ value = g_new(rpc_prog_info_value, 1);
value->proto = find_protocol_by_id(proto);
value->proto_id = proto;
value->ett = ett;
diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c
index 92b80ad836..a9c0cc9abc 100644
--- a/epan/dissectors/packet-sctp.c
+++ b/epan/dissectors/packet-sctp.c
@@ -2762,7 +2762,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn,
msg = find_message(stream_id, stream_seq_num, u_bit);
if (!msg) {
- msg = (sctp_frag_msg *)g_malloc (sizeof (sctp_frag_msg));
+ msg = g_new(sctp_frag_msg, 1);
msg->begins = NULL;
msg->ends = NULL;
msg->fragments = NULL;
@@ -2776,7 +2776,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn,
else
msg->ppi = ppi;
- key = (frag_key *)g_malloc(sizeof (frag_key));
+ key = g_new(frag_key, 1);
key->sport = sctp_info.sport;
key->dport = sctp_info.dport;
key->verification_tag = sctp_info.verification_tag;
@@ -2820,7 +2820,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn,
return NULL;
/* create new fragment */
- fragment = (sctp_fragment *)g_malloc (sizeof (sctp_fragment));
+ fragment = g_new(sctp_fragment, 1);
fragment->frame_num = pinfo->num;
fragment->tsn = tsn;
fragment->len = tvb_captured_length(tvb);
@@ -2850,7 +2850,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn,
/* save begin or end if necessary */
if (b_bit && !e_bit) {
- beginend = (sctp_frag_be *)g_malloc (sizeof (sctp_frag_be));
+ beginend = g_new(sctp_frag_be, 1);
beginend->fragment = fragment;
beginend->next = NULL;
@@ -2875,7 +2875,7 @@ add_fragment(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 tsn,
}
if (!b_bit && e_bit) {
- beginend = (sctp_frag_be *)g_malloc (sizeof (sctp_frag_be));
+ beginend = g_new(sctp_frag_be, 1);
beginend->fragment = fragment;
beginend->next = NULL;
diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c
index 39fe67a400..66f0349ac6 100644
--- a/epan/dissectors/packet-smb.c
+++ b/epan/dissectors/packet-smb.c
@@ -1286,7 +1286,7 @@ smb_eo_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const
entry = g_new(export_object_entry_t, 1);
entry->payload_data = NULL;
entry->payload_len = 0;
- new_file = (active_file *)g_malloc(sizeof(active_file));
+ new_file = g_new(active_file, 1);
new_file->tid = incoming_file.tid;
new_file->uid = incoming_file.uid;
new_file->fid = incoming_file.fid;
@@ -18010,7 +18010,7 @@ dissect_smb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* da
si->ct = (conv_tables_t *)conversation_get_proto_data(conversation, proto_smb);
if (!si->ct) {
/* No, not yet. create it and attach it to the conversation */
- si->ct = (conv_tables_t *)g_malloc(sizeof(conv_tables_t));
+ si->ct = g_new(conv_tables_t, 1);
conv_tables = g_slist_prepend(conv_tables, si->ct);
si->ct->matched = g_hash_table_new(smb_saved_info_hash_matched,
diff --git a/epan/dissectors/packet-smtp.c b/epan/dissectors/packet-smtp.c
index 096b6780cf..f83cca3689 100644
--- a/epan/dissectors/packet-smtp.c
+++ b/epan/dissectors/packet-smtp.c
@@ -429,7 +429,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
/*
* No - create one and attach it.
*/
- session_state = (struct smtp_session_state *)wmem_alloc0(wmem_file_scope(), sizeof(struct smtp_session_state));
+ session_state = wmem_new0(wmem_file_scope(), struct smtp_session_state);
session_state->smtp_state = SMTP_STATE_START;
session_state->auth_state = SMTP_AUTH_STATE_NONE;
session_state->msg_last = TRUE;
@@ -455,7 +455,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
/*
* Create a frame data structure and attach it to the packet.
*/
- spd_frame_data = (struct smtp_proto_data *)wmem_alloc0(wmem_file_scope(), sizeof(struct smtp_proto_data));
+ spd_frame_data = wmem_new0(wmem_file_scope(), struct smtp_proto_data);
spd_frame_data->conversation_id = conversation->conv_index;
spd_frame_data->more_frags = TRUE;
diff --git a/epan/dissectors/packet-snort-config.c b/epan/dissectors/packet-snort-config.c
index 1bf3f42d9a..0ced5c7407 100644
--- a/epan/dissectors/packet-snort-config.c
+++ b/epan/dissectors/packet-snort-config.c
@@ -741,7 +741,7 @@ static gboolean parse_rule(SnortConfig_t *snort_config, char *line, const char *
}
/* Allocate the rule itself */
- rule = (Rule_t*)g_malloc(sizeof(Rule_t));
+ rule = g_new(Rule_t, 1);
snort_debug_printf("looks like a rule: %s\n", line);
memset(rule, 0, sizeof(Rule_t));
@@ -905,7 +905,7 @@ void create_config(SnortConfig_t **snort_config, const char *snort_config_file)
snort_debug_printf("create_config (%s)\n", snort_config_file);
- *snort_config = (SnortConfig_t*)g_malloc(sizeof(SnortConfig_t));
+ *snort_config = g_new(SnortConfig_t, 1);
memset(*snort_config, 0, sizeof(SnortConfig_t));
/* Create rule table */
diff --git a/epan/dissectors/packet-snort.c b/epan/dissectors/packet-snort.c
index 2add440baf..5d9f1efe71 100644
--- a/epan/dissectors/packet-snort.c
+++ b/epan/dissectors/packet-snort.c
@@ -211,7 +211,7 @@ static void add_alert_to_session_tree(guint frame_number, Alert_t *alert)
Alerts_t *alerts = (Alerts_t*)wmem_tree_lookup32(current_session.alerts_tree, frame_number);
if (alerts == NULL) {
/* Create a new entry for the table */
- alerts = (Alerts_t*)g_malloc(sizeof(Alerts_t));
+ alerts = g_new(Alerts_t, 1);
/* Deep copy of alert */
alerts->alerts[0] = *alert;
alerts->num_alerts = 1;
diff --git a/epan/dissectors/packet-soupbintcp.c b/epan/dissectors/packet-soupbintcp.c
index 8a89ae0ba5..50eb41026a 100644
--- a/epan/dissectors/packet-soupbintcp.c
+++ b/epan/dissectors/packet-soupbintcp.c
@@ -205,7 +205,7 @@ dissect_soupbintcp_common(
0);
/* Store starting sequence number for session's packets */
- conv_data = (struct conv_data *)wmem_alloc(wmem_file_scope(), sizeof(struct conv_data));
+ conv_data = wmem_new(wmem_file_scope(), struct conv_data);
conv_data->next_seq = next_seq;
conversation_add_proto_data(conv, proto_soupbintcp, conv_data);
}
@@ -226,9 +226,7 @@ dissect_soupbintcp_common(
this_seq = 0;
}
- pdu_data = (struct pdu_data *)wmem_alloc(
- wmem_file_scope(),
- sizeof(struct pdu_data));
+ pdu_data = wmem_new(wmem_file_scope(), struct pdu_data);
pdu_data->seq_num = this_seq;
p_add_proto_data(wmem_file_scope(), pinfo, proto_soupbintcp, key, pdu_data);
}
diff --git a/epan/dissectors/packet-ssh.c b/epan/dissectors/packet-ssh.c
index 6b05061991..e909b437d2 100644
--- a/epan/dissectors/packet-ssh.c
+++ b/epan/dissectors/packet-ssh.c
@@ -458,7 +458,7 @@ dissect_ssh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
global_data = (struct ssh_flow_data *)conversation_get_proto_data(conversation, proto_ssh);
if (!global_data) {
- global_data = (struct ssh_flow_data *)wmem_alloc0(wmem_file_scope(), sizeof(struct ssh_flow_data));
+ global_data = wmem_new0(wmem_file_scope(), struct ssh_flow_data);
global_data->version = SSH_VERSION_UNKNOWN;
global_data->kex_specific_dissector = ssh_dissect_kex_dh;
global_data->peer_data[CLIENT_PEER_DATA].mac_length = -1;
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c
index 9b83e8d84c..3209042b40 100644
--- a/epan/dissectors/packet-tpncp.c
+++ b/epan/dissectors/packet-tpncp.c
@@ -801,8 +801,7 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file)
field = &data_fields_info[data_id];
current_data_id = data_id;
} else {
- field->p_next = (tpncp_data_field_info *) wmem_alloc(
- wmem_epan_scope(), sizeof (tpncp_data_field_info));
+ field->p_next = wmem_new(wmem_epan_scope(), tpncp_data_field_info);
if (!field->p_next)
return (-1);
field = field->p_next;
diff --git a/epan/dissectors/packet-twamp.c b/epan/dissectors/packet-twamp.c
index cd135fa61c..c2f13c269f 100644
--- a/epan/dissectors/packet-twamp.c
+++ b/epan/dissectors/packet-twamp.c
@@ -251,7 +251,7 @@ dissect_twamp_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void
/* try to find session from past visits */
if ((list = g_slist_find_custom(ct->sessions, &sender_port,
(GCompareFunc) find_twamp_session_by_sender_port)) == NULL) {
- session = (twamp_session_t *) g_malloc0(sizeof(twamp_session_t));
+ session = g_new0(twamp_session_t, 1);
session->sender_port = sender_port;
session->receiver_port = receiver_port;
session->accepted = 0;
diff --git a/epan/dissectors/packet-umts_rlc.c b/epan/dissectors/packet-umts_rlc.c
index 222a88eacb..e453c77ac3 100644
--- a/epan/dissectors/packet-umts_rlc.c
+++ b/epan/dissectors/packet-umts_rlc.c
@@ -378,7 +378,7 @@ rlc_channel_create(enum rlc_mode mode, packet_info *pinfo, struct atm_phdr *atm)
struct rlc_channel *ch;
int rv;
- ch = (struct rlc_channel *)g_malloc0(sizeof(struct rlc_channel));
+ ch = g_new0(struct rlc_channel, 1);
rv = rlc_channel_assign(ch, mode, pinfo, atm);
if (rv != 0) {
@@ -423,7 +423,7 @@ rlc_sdu_create(void)
{
struct rlc_sdu *sdu;
- sdu = (struct rlc_sdu *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_sdu));
+ sdu = wmem_new0(wmem_file_scope(), struct rlc_sdu);
return sdu;
}
@@ -484,7 +484,7 @@ rlc_frag_create(tvbuff_t *tvb, enum rlc_mode mode, packet_info *pinfo,
{
struct rlc_frag *frag;
- frag = (struct rlc_frag *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_frag));
+ frag = wmem_new0(wmem_file_scope(), struct rlc_frag);
rlc_frag_assign(frag, mode, pinfo, seq, li, atm);
rlc_frag_assign_data(frag, tvb, offset, length);
@@ -1302,7 +1302,7 @@ rlc_is_duplicate(enum rlc_mode mode, packet_info *pinfo, guint16 seq,
}
if(is_unseen) {
/* Add to list for the first time this frame is checked */
- seq_new = (struct rlc_seq *)wmem_alloc0(wmem_file_scope(), sizeof(struct rlc_seq));
+ seq_new = wmem_new0(wmem_file_scope(), struct rlc_seq);
*seq_new = seq_item;
seq_new->arrival = pinfo->abs_ts;
list->list = g_list_append(list->list, seq_new); /* insert in order of arrival */
@@ -1603,7 +1603,7 @@ rlc_decipher(tvbuff_t *tvb, packet_info * pinfo, proto_tree * tree, fp_info * fp
if(!tree){
/*Preserve counter value for next dissection round*/
guint32 * ciph;
- ciph = (guint32 *)g_malloc(sizeof(guint32)*2);
+ ciph = g_new(guint32, 2);
ciph[0] = ps_counter[rlcinf->rbid[pos]][0];
ciph[1] = ps_counter[rlcinf->rbid[pos]][1];
g_tree_insert(counter_map, GINT_TO_POINTER((gint)pinfo->num), ciph);
@@ -1643,7 +1643,7 @@ rlc_decipher(tvbuff_t *tvb, packet_info * pinfo, proto_tree * tree, fp_info * fp
if(!tree){/*Preserve counter for second packet analysis run*/
guint32 * ciph;
- ciph = (guint32 *)g_malloc(sizeof(guint32)*2);
+ ciph = g_new(guint32, 2);
ciph[0] = ps_counter[rlcinf->rbid[pos]][0];
ciph[1] = ps_counter[rlcinf->rbid[pos]][1];
g_tree_insert(counter_map, GINT_TO_POINTER((gint)pinfo->num+1), ciph);
diff --git a/epan/dissectors/packet-zvt.c b/epan/dissectors/packet-zvt.c
index e7f714a67c..80e8078027 100644
--- a/epan/dissectors/packet-zvt.c
+++ b/epan/dissectors/packet-zvt.c
@@ -477,8 +477,7 @@ dissect_zvt_tlv_seq(tvbuff_t *tvb, gint offset, guint16 seq_max_len,
gint ret;
if (!seq_info) {
- seq_info = (tlv_seq_info_t *)wmem_alloc(
- wmem_packet_scope(), sizeof(tlv_seq_info_t));
+ seq_info = wmem_new(wmem_packet_scope(), tlv_seq_info_t);
/* by default, text lines are using the CP437 charset
there's an object to change the encoding
diff --git a/epan/funnel.c b/epan/funnel.c
index 0ca21b8bb2..5e8cb24029 100644
--- a/epan/funnel.c
+++ b/epan/funnel.c
@@ -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);
diff --git a/epan/packet.c b/epan/packet.c
index 2085c770ed..e14fce8ec1 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -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;
diff --git a/epan/plugin_if.c b/epan/plugin_if.c
index 821053be6d..1231c533ef 100644
--- a/epan/plugin_if.c
+++ b/epan/plugin_if.c
@@ -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);
diff --git a/epan/prefs.c b/epan/prefs.c
index 68a535411f..8d564dcdf3 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -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. */
diff --git a/epan/print_stream.c b/epan/print_stream.c
index 3c3cb74092..a694216171 100644
--- a/epan/print_stream.c
+++ b/epan/print_stream.c
@@ -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;
diff --git a/epan/proto_data.c b/epan/proto_data.c
index 946a4795cb..5a851fab29 100644
--- a/epan/proto_data.c
+++ b/epan/proto_data.c
@@ -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;
diff --git a/epan/srt_table.c b/epan/srt_table.c
index bb528b5e33..56ce01c149 100644
--- a/epan/srt_table.c
+++ b/epan/srt_table.c
@@ -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;
diff --git a/epan/stat_tap_ui.c b/epan/stat_tap_ui.c
index e8020106e1..f9e5100621 100644
--- a/epan/stat_tap_ui.c
+++ b/epan/stat_tap_ui.c
@@ -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);
diff --git a/epan/stats_tree.c b/epan/stats_tree.c
index 18499582c9..be83cf36ba 100644
--- a/epan/stats_tree.c
+++ b/epan/stats_tree.c
@@ -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
diff --git a/epan/tap.c b/epan/tap.c
index e2997a6cd4..bb1145b999 100644
--- a/epan/tap.c
+++ b/epan/tap.c
@@ -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;
diff --git a/epan/tvbparse.c b/epan/tvbparse.c
index 91c7205baf..ade4624558 100644
--- a/epan/tvbparse.c
+++ b/epan/tvbparse.c
@@ -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;
diff --git a/epan/uat.c b/epan/uat.c
index ab3b0e99e7..e30518b88d 100644
--- a/epan/uat.c
+++ b/epan/uat.c
@@ -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;
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index bb131d6f65..da0a6a5b68 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -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;
diff --git a/epan/wslua/wslua_file_common.c b/epan/wslua/wslua_file_common.c
index 7c0421a751..2854a2de1b 100644
--- a/epan/wslua/wslua_file_common.c
+++ b/epan/wslua/wslua_file_common.c
@@ -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);
diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c
index 004f8725a6..627c25edc1 100644
--- a/epan/wslua/wslua_file_handler.c
+++ b/epan/wslua/wslua_file_handler.c
@@ -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;
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index 5dd45f753e..984848d79c 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -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;
diff --git a/epan/wslua/wslua_pref.c b/epan/wslua/wslua_pref.c
index 6c685c07a9..550633fc0c 100644
--- a/epan/wslua/wslua_pref.c
+++ b/epan/wslua/wslua_pref.c
@@ -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;
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c
index 0c1e806dcd..e857b2b4ca 100644
--- a/epan/wslua/wslua_proto.c
+++ b/epan/wslua/wslua_proto.c
@@ -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;
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c
index 41e5066c66..e3f63273df 100644
--- a/epan/wslua/wslua_proto_field.c
+++ b/epan/wslua/wslua_proto_field.c
@@ -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);
diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c
index 960973d492..c7474b6d70 100644
--- a/epan/wslua/wslua_tree.c
+++ b/epan/wslua/wslua_tree.c
@@ -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);
diff --git a/epan/wslua/wslua_util.c b/epan/wslua/wslua_util.c
index 187a7e1721..dda34edec2 100644
--- a/epan/wslua/wslua_util.c
+++ b/epan/wslua/wslua_util.c
@@ -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;
diff --git a/file.c b/file.c
index 7ad30ec37f..b20c34f25f 100644
--- a/file.c
+++ b/file.c
@@ -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;
diff --git a/fileset.c b/fileset.c
index 14436322d5..b02810a26d 100644
--- a/fileset.c
+++ b/fileset.c
@@ -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);
diff --git a/frame_tvbuff.c b/frame_tvbuff.c
index e337681754..17625c56f6 100644
--- a/frame_tvbuff.c
+++ b/frame_tvbuff.c
@@ -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);
diff --git a/plugins/codecs/sbc/sbc.c b/plugins/codecs/sbc/sbc.c
index 5b41d50c0c..ef6e8784fb 100644
--- a/plugins/codecs/sbc/sbc.c
+++ b/plugins/codecs/sbc/sbc.c
@@ -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;
diff --git a/plugins/epan/mate/mate_runtime.c b/plugins/epan/mate/mate_runtime.c
index c5f61888f9..30ebe23424 100644
--- a/plugins/epan/mate/mate_runtime.c
+++ b/plugins/epan/mate/mate_runtime.c
@@ -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);
diff --git a/plugins/epan/mate/mate_setup.c b/plugins/epan/mate/mate_setup.c
index 55febf7f14..797080ecca 100644
--- a/plugins/epan/mate/mate_setup.c
+++ b/plugins/epan/mate/mate_setup.c
@@ -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;
diff --git a/plugins/epan/mate/mate_util.c b/plugins/epan/mate/mate_util.c
index 4356b79cf1..84cd6ca830 100644
--- a/plugins/epan/mate/mate_util.c
+++ b/plugins/epan/mate/mate_util.c
@@ -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);
diff --git a/plugins/wiretap/usbdump/usbdump.c b/plugins/wiretap/usbdump/usbdump.c
index cd8f8754ba..3412ad1c3b 100644
--- a/plugins/wiretap/usbdump/usbdump.c
+++ b/plugins/wiretap/usbdump/usbdump.c
@@ -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;
diff --git a/rawshark.c b/rawshark.c
index 1a573d3ce3..4f6585603d 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -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);
diff --git a/ringbuffer.c b/ringbuffer.c
index 0a0267037e..c7d769e90c 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -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;
}
diff --git a/sharkd_session.c b/sharkd_session.c
index fdd58d5815..a5b90ba139 100644
--- a/sharkd_session.c
+++ b/sharkd_session.c
@@ -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);
}
diff --git a/tools/detect_bad_alloc_patterns.py b/tools/detect_bad_alloc_patterns.py
new file mode 100644
index 0000000000..33057f3a12
--- /dev/null
+++ b/tools/detect_bad_alloc_patterns.py
@@ -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()
diff --git a/tools/pre-commit b/tools/pre-commit
index 50c5230be0..51740eb6ef 100755
--- a/tools/pre-commit
+++ b/tools/pre-commit
@@ -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
diff --git a/ui/capture.c b/ui/capture.c
index 22ebc96984..a90d77136b 100644
--- a/ui/capture.c
+++ b/ui/capture.c
@@ -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);
diff --git a/ui/cli/tap-iostat.c b/ui/cli/tap-iostat.c
index 11794a2f1d..6640a59a09 100644
--- a/ui/cli/tap-iostat.c
+++ b/ui/cli/tap-iostat.c
@@ -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;
diff --git a/ui/cli/tap-sctpchunkstat.c b/ui/cli/tap-sctpchunkstat.c
index 303aa6729d..00949129bc 100644
--- a/ui/cli/tap-sctpchunkstat.c
+++ b/ui/cli/tap-sctpchunkstat.c
@@ -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 {
diff --git a/ui/filter_files.c b/ui/filter_files.c
index b289175a4e..299d84dd34 100644
--- a/ui/filter_files.c
+++ b/ui/filter_files.c
@@ -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);
diff --git a/ui/iface_lists.c b/ui/iface_lists.c
index 135a83d4b3..9ba39b9c5e 100644
--- a/ui/iface_lists.c
+++ b/ui/iface_lists.c
@@ -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);
diff --git a/ui/mcast_stream.c b/ui/mcast_stream.c
index 4824f9e672..74a704b630 100644
--- a/ui/mcast_stream.c
+++ b/ui/mcast_stream.c
@@ -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;
diff --git a/ui/preference_utils.c b/ui/preference_utils.c
index ef6ca14778..86fafc6452 100644
--- a/ui/preference_utils.c
+++ b/ui/preference_utils.c
@@ -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
diff --git a/ui/profile.c b/ui/profile.c
index a6742e5320..3a24f97ae1 100644
--- a/ui/profile.c
+++ b/ui/profile.c
@@ -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;
diff --git a/ui/recent.c b/ui/recent.c
index 8c24b32320..5bb4d54d0b 100644
--- a/ui/recent.c
+++ b/ui/recent.c
@@ -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;
diff --git a/ui/tap-rlc-graph.c b/ui/tap-rlc-graph.c
index f0f12862d9..7f20dcec78 100644
--- a/ui/tap-rlc-graph.c
+++ b/ui/tap-rlc-graph.c
@@ -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;
diff --git a/ui/tap-rtp-common.c b/ui/tap-rtp-common.c
index 613f8c5b1b..676c29a171 100644
--- a/ui/tap-rtp-common.c
+++ b/ui/tap-rtp-common.c
@@ -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;
diff --git a/ui/voip_calls.c b/ui/voip_calls.c
index c52548a95d..1018ed47c0 100644
--- a/ui/voip_calls.c
+++ b/ui/voip_calls.c
@@ -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:"");
diff --git a/wiretap/5views.c b/wiretap/5views.c
index b383884a1a..030840b221 100644
--- a/wiretap/5views.c
+++ b/wiretap/5views.c
@@ -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;
diff --git a/wiretap/aethra.c b/wiretap/aethra.c
index 63128d2d0f..0a5d23234f 100644
--- a/wiretap/aethra.c
+++ b/wiretap/aethra.c
@@ -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;
diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c
index 5a24215572..a03b313878 100644
--- a/wiretap/ascendtext.c
+++ b/wiretap/ascendtext.c
@@ -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
diff --git a/wiretap/capsa.c b/wiretap/capsa.c
index 55b027640c..3f77230d5c 100644
--- a/wiretap/capsa.c
+++ b/wiretap/capsa.c
@@ -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;
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index 9b82cfb949..a339367118 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -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 */
diff --git a/wiretap/csids.c b/wiretap/csids.c
index f0c7545ab1..c5cb757a62 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -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;
diff --git a/wiretap/erf.c b/wiretap/erf.c
index ffa4b9f198..b391a2d1f5 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -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;
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index e886cd06a7..8c50008c72 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -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;
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index 3ab324fa57..8e9e1cfa18 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -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;
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index 64facaee72..f652cd2693 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -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);
diff --git a/wiretap/iseries.c b/wiretap/iseries.c
index 1e43645a29..6f55fe110f 100644
--- a/wiretap/iseries.c
+++ b/wiretap/iseries.c
@@ -332,7 +332,7 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format)
iseries_t *iseries;
/* Save trace format for passing between packets */
- iseries = (iseries_t *) g_malloc (sizeof (iseries_t));
+ iseries = g_new(iseries_t, 1);
iseries->have_date = FALSE;
iseries->format = format;
diff --git a/wiretap/k12.c b/wiretap/k12.c
index 81a1697ab7..7b8861f666 100644
--- a/wiretap/k12.c
+++ b/wiretap/k12.c
@@ -1380,7 +1380,7 @@ gboolean k12_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_) {
wdh->subtype_write = k12_dump;
wdh->subtype_finish = k12_dump_finish;
- k12 = (k12_dump_t *)g_malloc(sizeof(k12_dump_t));
+ k12 = g_new(k12_dump_t, 1);
wdh->priv = (void *)k12;
k12->file_len = K12_FILE_HDR_LEN;
k12->num_of_records = 0;
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index 4174aa340b..227816e00d 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -453,7 +453,7 @@ done:
* Let's get some info from it. Note that we get wth->snapshot_length
* from a record later in the file. */
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LANALYZER;
- lanalyzer = (lanalyzer_t *)g_malloc(sizeof(lanalyzer_t));
+ lanalyzer = g_new(lanalyzer_t, 1);
lanalyzer->start = start;
wth->priv = (void *)lanalyzer;
wth->subtype_read = lanalyzer_read;
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index a5ce1303ef..81d66d1fd6 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -294,7 +294,7 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info)
}
/* This is a libpcap file */
- libpcap = (libpcap_t *)g_malloc(sizeof(libpcap_t));
+ libpcap = g_new(libpcap_t, 1);
libpcap->byte_swapped = byte_swapped;
libpcap->version_major = hdr.version_major;
libpcap->version_minor = hdr.version_minor;
diff --git a/wiretap/log3gpp.c b/wiretap/log3gpp.c
index f3076a71a8..91e15eb154 100644
--- a/wiretap/log3gpp.c
+++ b/wiretap/log3gpp.c
@@ -187,7 +187,7 @@ log3gpp_open(wtap *wth, int *err, gchar **err_info _U_)
}
/* Allocate struct and fill in timestamp (netmon re used)*/
- log3gpp = (log3gpp_t *)g_malloc(sizeof(log3gpp_t));
+ log3gpp = g_new(log3gpp_t, 1);
log3gpp->start_secs = timestamp;
log3gpp->start_usecs = usecs;
wth->priv = (void *)log3gpp;
diff --git a/wiretap/logcat.c b/wiretap/logcat.c
index 464abc74c5..9cb99e7f78 100644
--- a/wiretap/logcat.c
+++ b/wiretap/logcat.c
@@ -277,7 +277,7 @@ wtap_open_return_val logcat_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- logcat = (struct logcat_phdr *) g_malloc(sizeof(struct logcat_phdr));
+ logcat = g_new(struct logcat_phdr, 1);
logcat->version = version;
wth->priv = logcat;
diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c
index deba15a7a8..0b61cb362c 100644
--- a/wiretap/logcat_text.c
+++ b/wiretap/logcat_text.c
@@ -581,7 +581,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh,
static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type) {
struct dumper_t *dumper;
- dumper = (struct dumper_t *) g_malloc(sizeof(struct dumper_t));
+ dumper = g_new(struct dumper_t, 1);
dumper->type = dump_type;
wdh->priv = dumper;
diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c
index 587e2ed9e5..36ad7274ee 100644
--- a/wiretap/mp2t.c
+++ b/wiretap/mp2t.c
@@ -381,7 +381,7 @@ found:
wth->subtype_seek_read = mp2t_seek_read;
wth->snapshot_length = 0;
- mp2t = (mp2t_filetype_t*) g_malloc(sizeof(mp2t_filetype_t));
+ mp2t = g_new(mp2t_filetype_t, 1);
wth->priv = mp2t;
mp2t->start_offset = first;
diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c
index 745dadfb56..f7db4f96bc 100644
--- a/wiretap/mpeg.c
+++ b/wiretap/mpeg.c
@@ -252,7 +252,7 @@ good_magic:
wth->subtype_seek_read = mpeg_seek_read;
wth->snapshot_length = 0;
- mpeg = (mpeg_t *)g_malloc(sizeof(mpeg_t));
+ mpeg = g_new(mpeg_t, 1);
wth->priv = (void *)mpeg;
mpeg->now.secs = 0;
mpeg->now.nsecs = 0;
diff --git a/wiretap/netmon.c b/wiretap/netmon.c
index d15deaf068..d30c6176c7 100644
--- a/wiretap/netmon.c
+++ b/wiretap/netmon.c
@@ -464,7 +464,7 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info)
/* This is a netmon file */
wth->file_type_subtype = file_type;
- netmon = (netmon_t *)g_malloc0(sizeof(netmon_t));
+ netmon = g_new0(netmon_t, 1);
wth->priv = (void *)netmon;
wth->subtype_read = netmon_read;
wth->subtype_seek_read = netmon_seek_read;
@@ -1633,7 +1633,7 @@ gboolean netmon_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
wdh->subtype_write = netmon_dump;
wdh->subtype_finish = netmon_dump_finish;
- netmon = (netmon_dump_t *)g_malloc(sizeof(netmon_dump_t));
+ netmon = g_new(netmon_dump_t, 1);
wdh->priv = (void *)netmon;
netmon->frame_table_offset = CAPTUREFILE_HEADER_SIZE;
netmon->got_first_record_time = FALSE;
diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c
index 40a009f3eb..724f6953f0 100644
--- a/wiretap/netscaler.c
+++ b/wiretap/netscaler.c
@@ -796,7 +796,7 @@ wtap_open_return_val nstrace_open(wtap *wth, int *err, gchar **err_info)
}
wth->subtype_close = nstrace_close;
- nstrace = (nstrace_t *)g_malloc(sizeof(nstrace_t));
+ nstrace = g_new(nstrace_t, 1);
wth->priv = (void *)nstrace;
nstrace->pnstrace_buf = nstrace_buf;
nstrace->xxx_offset = 0;
@@ -2045,7 +2045,7 @@ gboolean nstrace_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_)
wdh->subtype_write = nstrace_dump;
- nstrace = (nstrace_dump_t *)g_malloc(sizeof(nstrace_dump_t));
+ nstrace = g_new(nstrace_dump_t, 1);
wdh->priv = (void *)nstrace;
nstrace->page_offset = 0;
if ((wdh->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0) ||
diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c
index de39e5021f..4d42bcaff3 100644
--- a/wiretap/network_instruments.c
+++ b/wiretap/network_instruments.c
@@ -159,7 +159,7 @@ wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_i
}
/* initialize the private state */
- private_state = (observer_dump_private_state *) g_malloc(sizeof(observer_dump_private_state));
+ private_state = g_new(observer_dump_private_state, 1);
private_state->time_format = TIME_INFO_LOCAL;
wth->priv = (void *) private_state;
@@ -675,7 +675,7 @@ gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err,
time_t system_time;
/* initialize the private state */
- private_state = (observer_dump_private_state *) g_malloc(sizeof(observer_dump_private_state));
+ private_state = g_new(observer_dump_private_state, 1);
private_state->packet_count = 0;
private_state->network_type = wtap_to_observer_encap(wdh->encap);
private_state->time_format = TIME_INFO_GMT;
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index 368575a721..dd940785d2 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -836,7 +836,7 @@ netxray_open(wtap *wth, int *err, gchar **err_info)
/* This is a netxray file */
wth->file_type_subtype = file_type;
- netxray = (netxray_t *)g_malloc(sizeof(netxray_t));
+ netxray = g_new(netxray_t, 1);
wth->priv = (void *)netxray;
wth->subtype_read = netxray_read;
wth->subtype_seek_read = netxray_seek_read;
@@ -1714,7 +1714,7 @@ netxray_dump_open_1_1(wtap_dumper *wdh, int *err, gchar **err_info _U_)
return FALSE;
wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE;
- netxray = (netxray_dump_t *)g_malloc(sizeof(netxray_dump_t));
+ netxray = g_new(netxray_dump_t, 1);
wdh->priv = (void *)netxray;
netxray->first_frame = TRUE;
netxray->start.secs = 0;
@@ -1901,7 +1901,7 @@ netxray_dump_open_2_0(wtap_dumper *wdh, int *err, gchar **err_info _U_)
wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE;
- netxray = (netxray_dump_t *)g_malloc(sizeof(netxray_dump_t));
+ netxray = g_new(netxray_dump_t, 1);
wdh->priv = (void *)netxray;
netxray->first_frame = TRUE;
netxray->start.secs = 0;
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c
index cd291baccd..7f94d61907 100644
--- a/wiretap/ngsniffer.c
+++ b/wiretap/ngsniffer.c
@@ -691,7 +691,7 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
}
/* This is a ngsniffer file */
- ngsniffer = (ngsniffer_t *)g_malloc(sizeof(ngsniffer_t));
+ ngsniffer = g_new(ngsniffer_t, 1);
wth->priv = (void *)ngsniffer;
ngsniffer->maj_vers = maj_vers;
ngsniffer->min_vers = pletoh16(&version.min_vers);
@@ -2030,7 +2030,7 @@ ngsniffer_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
wdh->subtype_write = ngsniffer_dump;
wdh->subtype_finish = ngsniffer_dump_finish;
- ngsniffer = (ngsniffer_dump_t *)g_malloc(sizeof(ngsniffer_dump_t));
+ ngsniffer = g_new(ngsniffer_dump_t, 1);
wdh->priv = (void *)ngsniffer;
ngsniffer->first_frame = TRUE;
ngsniffer->start = 0;
diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c
index f3814479c4..5460562312 100644
--- a/wiretap/packetlogger.c
+++ b/wiretap/packetlogger.c
@@ -191,7 +191,7 @@ wtap_open_return_val packetlogger_open(wtap *wth, int *err, gchar **err_info)
return WTAP_OPEN_ERROR;
/* This is a PacketLogger file */
- packetlogger = (packetlogger_t *)g_malloc(sizeof(packetlogger_t));
+ packetlogger = g_new(packetlogger_t, 1);
packetlogger->byte_swapped = byte_swapped;
wth->priv = (void *)packetlogger;
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index c7fcf06dce..0138d55616 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -2893,7 +2893,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
wth->file_encap = WTAP_ENCAP_UNKNOWN;
wth->snapshot_length = 0;
wth->file_tsprec = WTAP_TSPREC_UNKNOWN;
- pcapng = (pcapng_t *)g_malloc(sizeof(pcapng_t));
+ pcapng = g_new(pcapng_t, 1);
wth->priv = (void *)pcapng;
*pcapng = pn;
/*
diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c
index cdaa2d00ff..f1e6bb717a 100644
--- a/wiretap/peekclassic.c
+++ b/wiretap/peekclassic.c
@@ -316,7 +316,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
* At this point we have recognised the file type and have populated
* the whole ep_hdr structure in host byte order.
*/
- peekclassic = (peekclassic_t *)g_malloc(sizeof(peekclassic_t));
+ peekclassic = g_new(peekclassic_t, 1);
wth->priv = (void *)peekclassic;
peekclassic->reference_time = reference_time;
wth->file_encap = file_encap;
diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c
index ef8e80c42f..6b2dc4eea4 100644
--- a/wiretap/peektagged.c
+++ b/wiretap/peektagged.c
@@ -377,7 +377,7 @@ wtap_open_return_val peektagged_open(wtap *wth, int *err, gchar **err_info)
wth->subtype_seek_read = peektagged_seek_read;
wth->file_tsprec = WTAP_TSPREC_NSEC;
- peektagged = (peektagged_t *)g_malloc(sizeof(peektagged_t));
+ peektagged = g_new(peektagged_t, 1);
wth->priv = (void *)peektagged;
switch (mediaSubType) {
diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c
index 32bf813870..3fae6245b2 100644
--- a/wiretap/pppdump.c
+++ b/wiretap/pppdump.c
@@ -269,7 +269,7 @@ pppdump_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 5, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- state = (pppdump_t *)g_malloc(sizeof(pppdump_t));
+ state = g_new(pppdump_t, 1);
wth->priv = (void *)state;
state->timestamp = pntoh32(&buffer[1]);
state->tenths = 0;
diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c
index af4b73310f..9e927cbea4 100644
--- a/wiretap/stanag4607.c
+++ b/wiretap/stanag4607.c
@@ -185,7 +185,7 @@ wtap_open_return_val stanag4607_open(wtap *wth, int *err, gchar **err_info)
wth->file_encap = WTAP_ENCAP_STANAG_4607;
wth->snapshot_length = 0; /* not known */
- stanag4607 = (stanag4607_t *)g_malloc(sizeof(stanag4607_t));
+ stanag4607 = g_new(stanag4607_t, 1);
wth->priv = (void *)stanag4607;
stanag4607->base_secs = 0; /* unknown as of yet */
diff --git a/wiretap/visual.c b/wiretap/visual.c
index 98f4e680b3..8fd7613b0a 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -246,7 +246,7 @@ wtap_open_return_val visual_open(wtap *wth, int *err, gchar **err_info)
wth->file_tsprec = WTAP_TSPREC_MSEC;
/* Add Visual-specific information to the wiretap struct for later use. */
- visual = (struct visual_read_info *)g_malloc(sizeof(struct visual_read_info));
+ visual = g_new(struct visual_read_info, 1);
wth->priv = (void *)visual;
visual->num_pkts = pletoh32(&vfile_hdr.num_pkts);
visual->start_time = pletoh32(&vfile_hdr.start_time);
@@ -612,7 +612,7 @@ gboolean visual_dump_open(wtap_dumper *wdh, int *err, gchar **err_info _U_)
/* Create a struct to hold file information for the duration
of the write */
- visual = (struct visual_write_info *)g_malloc(sizeof(struct visual_write_info));
+ visual = g_new(struct visual_write_info, 1);
wdh->priv = (void *)visual;
visual->index_table_index = 0;
visual->index_table_size = 1024;
diff --git a/wiretap/vwr.c b/wiretap/vwr.c
index 05c7d33d61..a316020a89 100644
--- a/wiretap/vwr.c
+++ b/wiretap/vwr.c
@@ -822,7 +822,7 @@ wtap_open_return_val vwr_open(wtap *wth, int *err, gchar **err_info)
}
/* This is a vwr file */
- vwr = (vwr_t *)g_malloc0(sizeof(vwr_t));
+ vwr = g_new0(vwr_t, 1);
wth->priv = (void *)vwr;
vwr->FPGA_VERSION = fpgaVer;
diff --git a/wsutil/codecs.c b/wsutil/codecs.c
index 5943a73c43..c4519dbb42 100644
--- a/wsutil/codecs.c
+++ b/wsutil/codecs.c
@@ -98,7 +98,7 @@ register_codec(const char *name, codec_init_fn init_fn, codec_release_fn release
if (g_hash_table_lookup(registered_codecs, name) != NULL)
return FALSE; /* report an error, or have our caller do it? */
- handle = (struct codec_handle *)g_malloc(sizeof (struct codec_handle));
+ handle = g_new(struct codec_handle, 1);
handle->name = name;
handle->init_fn = init_fn;
handle->release_fn = release_fn;
diff --git a/wsutil/plugins.c b/wsutil/plugins.c
index f4fa859b48..eb2cfa3f33 100644
--- a/wsutil/plugins.c
+++ b/wsutil/plugins.c
@@ -196,7 +196,7 @@ DIAG_OFF_PEDANTIC
((plugin_register_func)symbol)();
DIAG_ON_PEDANTIC
- new_plug = (plugin *)g_malloc(sizeof(plugin));
+ new_plug = g_new(plugin, 1);
new_plug->handle = handle;
new_plug->name = g_strdup(name);
new_plug->version = plug_version;