[PATCH 03/17] virDomainMomentAssignDef: Simplify error handling

Peter Krempa pkrempa at redhat.com
Wed Jan 12 18:10:03 UTC 2022


Remove error handling from the call to 'virDomainMomentObjNew' as it
can't return NULL and replace 'virHashAddEntry' by 'g_hash_table_insert'
as we've already checked that snapshot with such name doesn't exist in
the hash table. This removes handling for two impossible errors.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/virdomainmomentobjlist.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
index 8993c2310b..2f2467d13f 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -245,14 +245,9 @@ virDomainMomentAssignDef(virDomainMomentObjList *moments,
         return NULL;
     }

-    if (!(moment = virDomainMomentObjNew()))
-        return NULL;
-
-    if (virHashAddEntry(moments->objs, def->name, moment) < 0) {
-        VIR_FREE(moment);
-        return NULL;
-    }
+    moment = virDomainMomentObjNew();
     moment->def = def;
+    g_hash_table_insert(moments->objs, g_strdup(def->name), moment);

     return moment;
 }
-- 
2.31.1




More information about the libvir-list mailing list