Skip to content

Commit

Permalink
tcp_protocol_list_init(): allocate once instead of realloc each time
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito authored and yrutschle committed Apr 13, 2024
1 parent ae7530e commit 1ddf45b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tcp-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ int probe_client_protocol(struct connection *cnx)

static void tcp_protocol_list_init(void)
{
tcp_protocols = calloc(cfg.protocols_len, sizeof(tcp_protocols));
CHECK_ALLOC(tcp_protocols, "tcp_protocols");
for (int i = 0; i < cfg.protocols_len; i++) {
struct sslhcfg_protocols_item* p = &cfg.protocols[i];
if (!p->is_udp) {
tcp_protocols[tcp_protocols_len] = p;
tcp_protocols_len++;
tcp_protocols = realloc(tcp_protocols, tcp_protocols_len * sizeof(*tcp_protocols));
CHECK_ALLOC(tcp_protocols, "realloc");
tcp_protocols[tcp_protocols_len-1] = p;
}
}
}
Expand Down

0 comments on commit 1ddf45b

Please sign in to comment.