render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From ca0f45dfc891bfb383e365376c6a2b4bb2ae3ba3 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <ca0f45dfc891bfb383e365376c6a2b4bb2ae3ba3@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Tue, 4 Feb 2020 15:08:20 +0100
a41c76
Subject: [PATCH] virHashAddOrUpdateEntry: Simplify allocation of new entry
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Use g_new0 and skip checking of the return value of keyCopy callback
a41c76
as both are bound to return a valid pointer.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 509ddcfde2af565a63ba193d41395aa99ea4744e)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
a41c76
Message-Id: <3e351cf75e5514f54bd2e6dc799792248dfe1f82.1580824112.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/util/virhash.c | 9 ++-------
a41c76
 1 file changed, 2 insertions(+), 7 deletions(-)
a41c76
a41c76
diff --git a/src/util/virhash.c b/src/util/virhash.c
a41c76
index c57d9f8292..36a2d312fc 100644
a41c76
--- a/src/util/virhash.c
a41c76
+++ b/src/util/virhash.c
a41c76
@@ -344,7 +344,6 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
a41c76
     size_t key, len = 0;
a41c76
     virHashEntryPtr entry;
a41c76
     virHashEntryPtr last = NULL;
a41c76
-    void *new_name;
a41c76
 
a41c76
     if ((table == NULL) || (name == NULL))
a41c76
         return -1;
a41c76
@@ -374,12 +373,8 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
a41c76
         len++;
a41c76
     }
a41c76
 
a41c76
-    if (VIR_ALLOC(entry) < 0 || !(new_name = table->keyCopy(name))) {
a41c76
-        VIR_FREE(entry);
a41c76
-        return -1;
a41c76
-    }
a41c76
-
a41c76
-    entry->name = new_name;
a41c76
+    entry = g_new0(virHashEntry, 1);
a41c76
+    entry->name = table->keyCopy(name);
a41c76
     entry->payload = userdata;
a41c76
 
a41c76
     if (last)
a41c76
-- 
a41c76
2.25.0
a41c76