render / rpms / libvirt

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