aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
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 /wiretap
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.
Diffstat (limited to 'wiretap')
-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
32 files changed, 52 insertions, 52 deletions
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;