aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorMoshe Kaplan <me@moshekaplan.com>2020-12-22 15:21:37 -0500
committerMoshe Kaplan <me@moshekaplan.com>2020-12-23 14:07:18 +0000
commit6bce7b859aaaabfa7a81db01a387fcb401d685bb (patch)
tree24edd1a4f9391590a7ceb9381adfb7b05c76b9a3 /epan
parent180b5e5dc0ad393e1af141f4bb5ee66e31ce8d7e (diff)
Detect and replace bad allocation patterns (more)
Extension of !1413, to improve regex, detect additional opportunities to replace `g_malloc` with `g_new`, and fix them.
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-knxip_decrypt.c10
-rw-r--r--epan/dissectors/packet-tacacs.c4
-rw-r--r--epan/stats_tree.c2
3 files changed, 8 insertions, 8 deletions
diff --git a/epan/dissectors/packet-knxip_decrypt.c b/epan/dissectors/packet-knxip_decrypt.c
index 3e262bb6ad..7b53c9c9aa 100644
--- a/epan/dissectors/packet-knxip_decrypt.c
+++ b/epan/dissectors/packet-knxip_decrypt.c
@@ -334,7 +334,7 @@ static void add_mca_key( const guint8 mca[ IPA_SIZE ], const gchar* text, guint8
fprintf_hex( f2, key, KNX_KEY_LENGTH );
}
- mca_key = (struct knx_keyring_mca_keys*) wmem_alloc( wmem_epan_scope(), sizeof( struct knx_keyring_mca_keys ) );
+ mca_key = wmem_new(wmem_epan_scope(), struct knx_keyring_mca_keys);
if( mca_key )
{
@@ -381,7 +381,7 @@ static void add_ga_key( guint16 ga, const gchar* text, guint8 password_hash[], g
fprintf_hex( f2, key, KNX_KEY_LENGTH );
}
- ga_key = (struct knx_keyring_ga_keys*) wmem_alloc( wmem_epan_scope(), sizeof( struct knx_keyring_ga_keys ) );
+ ga_key = wmem_new(wmem_epan_scope(), struct knx_keyring_ga_keys);
if( ga_key )
{
@@ -419,7 +419,7 @@ static void add_ga_sender( guint16 ga, const gchar* text, FILE* f2 )
fprintf( f2, "GA %u/%u/%u sender %u.%u.%u\n", (ga >> 11) & 0x1F, (ga >> 8) & 0x7, ga & 0xFF, (ia >> 12) & 0xF, (ia >> 8) & 0xF, ia & 0xFF );
}
- ga_sender = (struct knx_keyring_ga_senders*) wmem_alloc( wmem_epan_scope(), sizeof( struct knx_keyring_ga_senders ) );
+ ga_sender = wmem_new(wmem_epan_scope(), struct knx_keyring_ga_senders);
if( ga_sender )
{
@@ -465,7 +465,7 @@ static void add_ia_key( guint16 ia, const gchar* text, guint8 password_hash[], g
fprintf_hex( f2, key, KNX_KEY_LENGTH );
}
- ia_key = (struct knx_keyring_ia_keys*) wmem_alloc( wmem_epan_scope(), sizeof( struct knx_keyring_ia_keys ) );
+ ia_key = wmem_new(wmem_epan_scope(), struct knx_keyring_ia_keys);
if( ia_key )
{
@@ -504,7 +504,7 @@ static void add_ia_seq( guint16 ia, const gchar* text, FILE* f2 )
fprintf( f2, "IA %u.%u.%u SeqNr %" G_GINT64_MODIFIER "u\n", (ia >> 12) & 0xF, (ia >> 8) & 0xF, ia & 0xFF, seq );
}
- ia_seq = (struct knx_keyring_ia_seqs*) wmem_alloc( wmem_epan_scope(), sizeof( struct knx_keyring_ia_seqs ) );
+ ia_seq = wmem_new(wmem_epan_scope(), struct knx_keyring_ia_seqs);
if( ia_seq )
{
diff --git a/epan/dissectors/packet-tacacs.c b/epan/dissectors/packet-tacacs.c
index 20764eb803..223678d3d5 100644
--- a/epan/dissectors/packet-tacacs.c
+++ b/epan/dissectors/packet-tacacs.c
@@ -792,7 +792,7 @@ mkipv4_address( address **addr, const char *str_addr )
int ret;
char *addr_data;
- *addr=(address *)g_malloc( sizeof(address) );
+ *addr=g_new(address, 1);
addr_data=(char *)g_malloc( 4 );
ret = str_to_ip(str_addr, addr_data);
if (ret)
@@ -804,7 +804,7 @@ static void
parse_tuple( char *key_from_option )
{
char *client,*key;
- tacplus_key_entry *tacplus_data=(tacplus_key_entry *)g_malloc( sizeof(tacplus_key_entry) );
+ tacplus_key_entry *tacplus_data=g_new(tacplus_key_entry, 1);
/*
ws_debug_printf("keys: %s\n", key_from_option );
*/
diff --git a/epan/stats_tree.c b/epan/stats_tree.c
index be83cf36ba..fa8918cc0b 100644
--- a/epan/stats_tree.c
+++ b/epan/stats_tree.c
@@ -270,7 +270,7 @@ stats_tree_register_with_group(const char *tapname, const char *abbr, const char
stat_tree_packet_cb packet, stat_tree_init_cb init,
stat_tree_cleanup_cb cleanup, register_stat_group_t stat_group)
{
- stats_tree_cfg *cfg = (stats_tree_cfg *)g_malloc0( sizeof(stats_tree_cfg) );
+ stats_tree_cfg *cfg = g_new0(stats_tree_cfg, 1);
/* at the very least the abbrev and the packet function should be given */
g_assert( tapname && abbr && packet );