From 25d45433b839732ccf07756c1ca6963c0cfac863 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 23 Mar 2021 17:11:42 +0100 Subject: [PATCH] virResctrlAllocNewFromInfo: Restrict variable scope and use automatic freeing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Move variables into the loop which uses them and use automatic freeing for temporarily allocated variables. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/util/virresctrl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index fbc8e9c766..5e7c391524 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1811,27 +1811,26 @@ static virResctrlAllocPtr virResctrlAllocNewFromInfo(virResctrlInfoPtr info) { size_t i = 0; - size_t j = 0; - size_t k = 0; virResctrlAllocPtr ret = virResctrlAllocNew(); - virBitmapPtr mask = NULL; if (!ret) return NULL; for (i = 0; i < info->nlevels; i++) { virResctrlInfoPerLevelPtr i_level = info->levels[i]; + size_t j = 0; if (!i_level) continue; for (j = 0; j < VIR_CACHE_TYPE_LAST; j++) { virResctrlInfoPerTypePtr i_type = i_level->types[j]; + g_autoptr(virBitmap) mask = NULL; + size_t k = 0; if (!i_type) continue; - virBitmapFree(mask); mask = virBitmapNew(i_type->bits); virBitmapSetAll(mask); @@ -1856,7 +1855,6 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) } cleanup: - virBitmapFree(mask); return ret; error: virObjectUnref(ret); -- 2.47.2