From ebfe9b1a158a917f89bda45e4d93b9a8d88339ad Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 12 Jan 2022 10:28:23 +0100
Subject: [PATCH] virDomainMomentAssignDef: Simplify error handling
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@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;
 }