Blob Blame History Raw
From 946b656463d4947801be9ac138113feec1f0cf48 Mon Sep 17 00:00:00 2001
Message-Id: <946b656463d4947801be9ac138113feec1f0cf48@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 4 Feb 2020 15:08:19 +0100
Subject: [PATCH] virhash: Fix the expectations of virHashKeyEqual
 implementations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Tweak the return value expectation comment so that it doesn't
necessarily require to allocate memory and refactor the implementations.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 6cf3ec4428c6b3f3dae30286e50bb7396615cf56)

https://bugzilla.redhat.com/show_bug.cgi?id=1207659
Message-Id: <2b3b0d52d6baa6ddb67b26520cfae1a5f247d803.1580824112.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/domain_addr.c | 5 +----
 src/util/virhash.c     | 4 +---
 src/util/virhash.h     | 3 ++-
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index f07b3d9725..e0be655772 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -997,10 +997,7 @@ virZPCIAddrKeyEqual(const void *namea,
 static void *
 virZPCIAddrKeyCopy(const void *name)
 {
-    unsigned int *copy;
-
-    if (VIR_ALLOC(copy) < 0)
-        return NULL;
+    unsigned int *copy = g_new0(unsigned int, 1);
 
     *copy = *((unsigned int *)name);
     return (void *)copy;
diff --git a/src/util/virhash.c b/src/util/virhash.c
index d5c5e017a1..c57d9f8292 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -94,9 +94,7 @@ static bool virHashStrEqual(const void *namea, const void *nameb)
 
 static void *virHashStrCopy(const void *name)
 {
-    char *ret;
-    ret = g_strdup(name);
-    return ret;
+    return g_strdup(name);
 }
 
 
diff --git a/src/util/virhash.h b/src/util/virhash.h
index 08f99d8a3d..cb59fb639b 100644
--- a/src/util/virhash.h
+++ b/src/util/virhash.h
@@ -83,7 +83,8 @@ typedef bool (*virHashKeyEqual)(const void *namea, const void *nameb);
  * Create a copy of the hash key, duplicating
  * memory allocation where applicable
  *
- * Returns a newly allocated copy of @name
+ * Returns a copy of @name which will eventually be passed to the
+ * 'virHashKeyFree' callback at the end of its lifetime.
  */
 typedef void *(*virHashKeyCopy)(const void *name);
 /**
-- 
2.25.0