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