aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
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 /dumpcap.c
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 'dumpcap.c')
-rw-r--r--dumpcap.c8
1 files changed, 4 insertions, 4 deletions
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;