From 61af0b2e090bfbd1d9e79fcd7f3415338aeeac6e Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sat, 10 Sep 2022 16:41:20 +0200 Subject: [PATCH] fix cppcheck complains Signed-off-by: Toni Uhlig --- gap.c | 5 ++++- log.c | 7 ++++--- systemd-sslh-generator.c | 8 ++++++-- tcp-probe.c | 1 + udp-listener.c | 1 + 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gap.c b/gap.c index a0adfbc..ce2202a 100644 --- a/gap.c +++ b/gap.c @@ -48,7 +48,10 @@ gap_array* gap_init(int len) gap->len = gap_len_alloc(elem_size); if (gap->len < len) gap->len = len; gap->array = malloc(gap->len * elem_size); - if (!gap->array) return NULL; + if (!gap->array) { + free(gap); + return NULL; + } for (int i = 0; i < gap->len; i++) gap->array[i] = NULL; diff --git a/log.c b/log.c index 3204595..7417af5 100644 --- a/log.c +++ b/log.c @@ -107,10 +107,11 @@ void print_message(msg_info info, const char* str, ...) { va_list ap; - va_start(ap, str); - - if ((*info.verbose & MSG_STDOUT) && ! cfg.inetd) + if ((*info.verbose & MSG_STDOUT) && ! cfg.inetd) { + va_start(ap, str); vfprintf(stderr, str, ap); + va_end(ap); + } if (*info.verbose & MSG_SYSLOG) { va_start(ap, str); diff --git a/systemd-sslh-generator.c b/systemd-sslh-generator.c index c8045f1..640e7cf 100644 --- a/systemd-sslh-generator.c +++ b/systemd-sslh-generator.c @@ -55,9 +55,12 @@ static int get_listen_from_conf(const char *filename, char **listen[]) { config_setting_source_line(addr)); return -1; } else { - (*listen)[i] = malloc(strlen(resolve_listen(hostname, port))); + char *resolved_listen = resolve_listen(hostname, port); + + (*listen)[i] = malloc(strlen(resolved_listen)); CHECK_ALLOC((*listen)[i], "malloc"); - strcpy((*listen)[i], resolve_listen(hostname, port)); + strcpy((*listen)[i], resolved_listen); + free(resolved_listen); } } } @@ -125,6 +128,7 @@ static int gen_sslh_config(char *runtime_unit_dir) { strcpy(runtime_conf, runtime_unit_dir); strcat(runtime_conf, unit_file); runtime_conf_fd = fopen(runtime_conf, "w"); + free(runtime_conf); } diff --git a/tcp-probe.c b/tcp-probe.c index ed4060b..b628e44 100644 --- a/tcp-probe.c +++ b/tcp-probe.c @@ -65,6 +65,7 @@ static void tcp_protocol_list_init(void) if (!p->is_udp) { 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; } } diff --git a/udp-listener.c b/udp-listener.c index 179cc93..a959a03 100644 --- a/udp-listener.c +++ b/udp-listener.c @@ -86,6 +86,7 @@ static void udp_protocol_list_init(void) if (p->is_udp) { udp_protocols_len++; udp_protocols = realloc(udp_protocols, udp_protocols_len * sizeof(*udp_protocols)); + CHECK_ALLOC(udp_protocols, "realloc"); udp_protocols[udp_protocols_len-1] = p; } }