From add18b06c742e324ef1328e150c531f63ea513c3 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 3 Feb 2021 13:42:00 +0100 Subject: [PATCH] virNWFilterVarCombIter: Allocate 'iter' member separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch to the more common approach of having arrays allocated separately rather than trailing the struct. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrangé --- src/conf/nwfilter_params.c | 6 ++++-- src/conf/nwfilter_params.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 18b64e373b..1be492759a 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -304,6 +304,8 @@ virNWFilterVarCombIterFree(virNWFilterVarCombIterPtr ci) for (i = 0; i < ci->nIter; i++) g_free(ci->iter[i].varNames); + g_free(ci->iter); + g_free(ci); } @@ -465,8 +467,8 @@ virNWFilterVarCombIterCreate(GHashTable *hash, int iterIndex = -1; unsigned int nextIntIterId = VIR_NWFILTER_MAX_ITERID + 1; - if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < 0) - return NULL; + res = g_new0(virNWFilterVarCombIter, 1); + res->iter = g_new0(virNWFilterVarCombIterEntry, nVarAccess + 1); res->hashTable = hash; diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index 05a6a43399..59068b8ae9 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -137,7 +137,7 @@ typedef virNWFilterVarCombIter *virNWFilterVarCombIterPtr; struct _virNWFilterVarCombIter { GHashTable *hashTable; size_t nIter; - virNWFilterVarCombIterEntry iter[0]; + virNWFilterVarCombIterEntryPtr iter; }; virNWFilterVarCombIterPtr virNWFilterVarCombIterCreate( GHashTable *hash,