From: Peter Krempa <[email protected]>

Set 'nhugepages' directly to the potential maximum amount of hugepages
as we'll parse less than that only on error at which point the function
freeing the domain definition needs to clean up also the partially
filled entries.

Closes: https://gitlab.com/libvirt/libvirt/-/work_items/951
Signed-off-by: Peter Krempa <[email protected]>
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f3179926c9..bb195264c4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19513,12 +19513,12 @@ virDomainDefParseMemory(virDomainDef *def,

         if (n) {
             def->mem.hugepages = g_new0(virDomainHugePage, n);
+            def->mem.nhugepages = n;

             for (i = 0; i < n; i++) {
                 if (virDomainHugepagesParseXML(nodes[i], ctxt,
                                                &def->mem.hugepages[i]) < 0)
                     return -1;
-                def->mem.nhugepages++;
             }

             VIR_FREE(nodes);
-- 
2.56.0

Reply via email to