render / rpms / libvirt

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