From 09302e89096c70fece8d8e8d3a4b8acb236e397b Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 12 Oct 2014 19:20:58 -0400 Subject: Free ports when there are no valid ones --- other/bootstrap_daemon/tox-bootstrapd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'other/bootstrap_daemon/tox-bootstrapd.c') diff --git a/other/bootstrap_daemon/tox-bootstrapd.c b/other/bootstrap_daemon/tox-bootstrapd.c index 7e78da4e..1b69014c 100644 --- a/other/bootstrap_daemon/tox-bootstrapd.c +++ b/other/bootstrap_daemon/tox-bootstrapd.c @@ -161,7 +161,12 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } // the loop above skips invalid ports, so we adjust the allocated memory size - *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); + if ((*tcp_relay_port_count) > 0) { + *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); + } else { + free(*tcp_relay_port); + *tcp_relay_port = NULL; + } return; } @@ -210,8 +215,11 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } // the loop above skips invalid ports, so we adjust the allocated memory size - if ((*tcp_relay_port_count) * sizeof(uint16_t) > 0) { + if ((*tcp_relay_port_count) > 0) { *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); + } else { + free(*tcp_relay_port); + *tcp_relay_port = NULL; } } -- cgit v1.2.3