From 721aa6f74f17f56dd82873aefffb2d6683918b79 Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Tue, 30 Nov 2021 10:55:34 +0000 Subject: Replace malloc+memset with calloc There are a number of places where we `malloc` some memory and then `memset` it to zero. Use `calloc` instead. Signed-off-by: Jeremy Sowden Signed-off-by: Pablo Neira Ayuso --- output/pgsql/ulogd_output_PGSQL.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'output/pgsql') diff --git a/output/pgsql/ulogd_output_PGSQL.c b/output/pgsql/ulogd_output_PGSQL.c index fda289e..f5a2823 100644 --- a/output/pgsql/ulogd_output_PGSQL.c +++ b/output/pgsql/ulogd_output_PGSQL.c @@ -181,8 +181,7 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi) upi->input.num_keys = PQntuples(pi->pgres); ulogd_log(ULOGD_DEBUG, "%u fields in table\n", upi->input.num_keys); - upi->input.keys = malloc(sizeof(struct ulogd_key) * - upi->input.num_keys); + upi->input.keys = calloc(upi->input.num_keys, sizeof(*upi->input.keys)); if (!upi->input.keys) { upi->input.num_keys = 0; ulogd_log(ULOGD_ERROR, "ENOMEM\n"); @@ -190,9 +189,6 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi) return -ENOMEM; } - memset(upi->input.keys, 0, sizeof(struct ulogd_key) * - upi->input.num_keys); - for (i = 0; i < PQntuples(pi->pgres); i++) { char buf[ULOGD_MAX_KEYLEN+1]; char *underscore; -- cgit v1.2.3