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 /sharkd_session.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 'sharkd_session.c')
-rw-r--r-- | sharkd_session.c | 8 |
1 files changed, 4 insertions, 4 deletions
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); } |