diff options
author | Moshe Kaplan <me@moshekaplan.com> | 2020-12-20 21:30:28 -0500 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2020-12-22 14:56:38 +0000 |
commit | e16166a74cca1d66e2c302e257cf94aebb380599 (patch) | |
tree | 8834b4b8390fca83dd7bc1b4b9e6a7bb276e1d7e /ui/iface_lists.c | |
parent | 7b27b444cbd94853b399da770e0dad4b91ef23ac (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 'ui/iface_lists.c')
-rw-r--r-- | ui/iface_lists.c | 4 |
1 files changed, 2 insertions, 2 deletions
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); |