[libvirt] [PATCH v2 02/11] virDomainObjListAddLocked: Set vm->def only in success path

Michal Privoznik mprivozn at redhat.com
Wed Jun 5 09:09:10 UTC 2019


Because of past limitation of virDomainObjListAddObjLocked() we
had to set vm->def even before the object was on the domains
list.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
Reviewed-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/conf/virdomainobjlist.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 28cccd0035..1086aec421 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -337,12 +337,11 @@ virDomainObjListAddLocked(virDomainObjListPtr doms,
 
         if (!(vm = virDomainObjNew(xmlopt)))
             goto error;
+
+        if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) < 0)
+            goto error;
+
         vm->def = def;
-
-        if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) < 0) {
-            vm->def = NULL;
-            goto error;
-        }
     }
 
     return vm;
-- 
2.21.0




More information about the libvir-list mailing list