From 5e4262b9ac6214b693854281dd0c0748d6a2f883 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 17 Feb 2025 13:01:39 +0100 Subject: [PATCH] virDomainResctrlMonDefParse: Refactor temporary variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decrease scope of temporary variables so that they don't have to be autofreed and VIR_FREE()d at the same time. Remove unneeded checks and temporary variables. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 49555efc56..1da59cf83a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18144,8 +18144,6 @@ virDomainResctrlMonDefParse(virDomainDef *def, int rv = -1; int ret = -1; g_autofree xmlNodePtr *nodes = NULL; - g_autofree char *tmp = NULL; - g_autofree char *id = NULL; ctxt->node = node; @@ -18153,6 +18151,8 @@ virDomainResctrlMonDefParse(virDomainDef *def, goto cleanup; for (i = 0; i < n; i++) { + g_autofree char *id = NULL; + domresmon = g_new0(virDomainResctrlMonDef, 1); domresmon->tag = tag; @@ -18188,12 +18188,9 @@ virDomainResctrlMonDefParse(virDomainDef *def, * associated allocation, set monitor's id to the same value * as the allocation. */ if (rv == 1) { - const char *alloc_id = virResctrlAllocGetID(resctrl->alloc); - - id = g_strdup(alloc_id); + id = g_strdup(virResctrlAllocGetID(resctrl->alloc)); } else { - if (!(tmp = virBitmapFormat(domresmon->vcpus))) - goto cleanup; + g_autofree char *tmp = virBitmapFormat(domresmon->vcpus); id = g_strdup_printf("vcpus_%s", tmp); } @@ -18204,9 +18201,6 @@ virDomainResctrlMonDefParse(virDomainDef *def, goto cleanup; VIR_APPEND_ELEMENT(resctrl->monitors, resctrl->nmonitors, domresmon); - - VIR_FREE(id); - VIR_FREE(tmp); } ret = 0;