Blame SOURCES/libvirt-virhash-Fix-the-expectations-of-virHashKeyEqual-implementations.patch

a41c76
From 946b656463d4947801be9ac138113feec1f0cf48 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <946b656463d4947801be9ac138113feec1f0cf48@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Tue, 4 Feb 2020 15:08:19 +0100
a41c76
Subject: [PATCH] virhash: Fix the expectations of virHashKeyEqual
a41c76
 implementations
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Tweak the return value expectation comment so that it doesn't
a41c76
necessarily require to allocate memory and refactor the implementations.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 6cf3ec4428c6b3f3dae30286e50bb7396615cf56)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
a41c76
Message-Id: <2b3b0d52d6baa6ddb67b26520cfae1a5f247d803.1580824112.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/conf/domain_addr.c | 5 +----
a41c76
 src/util/virhash.c     | 4 +---
a41c76
 src/util/virhash.h     | 3 ++-
a41c76
 3 files changed, 4 insertions(+), 8 deletions(-)
a41c76
a41c76
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
a41c76
index f07b3d9725..e0be655772 100644
a41c76
--- a/src/conf/domain_addr.c
a41c76
+++ b/src/conf/domain_addr.c
a41c76
@@ -997,10 +997,7 @@ virZPCIAddrKeyEqual(const void *namea,
a41c76
 static void *
a41c76
 virZPCIAddrKeyCopy(const void *name)
a41c76
 {
a41c76
-    unsigned int *copy;
a41c76
-
a41c76
-    if (VIR_ALLOC(copy) < 0)
a41c76
-        return NULL;
a41c76
+    unsigned int *copy = g_new0(unsigned int, 1);
a41c76
 
a41c76
     *copy = *((unsigned int *)name);
a41c76
     return (void *)copy;
a41c76
diff --git a/src/util/virhash.c b/src/util/virhash.c
a41c76
index d5c5e017a1..c57d9f8292 100644
a41c76
--- a/src/util/virhash.c
a41c76
+++ b/src/util/virhash.c
a41c76
@@ -94,9 +94,7 @@ static bool virHashStrEqual(const void *namea, const void *nameb)
a41c76
 
a41c76
 static void *virHashStrCopy(const void *name)
a41c76
 {
a41c76
-    char *ret;
a41c76
-    ret = g_strdup(name);
a41c76
-    return ret;
a41c76
+    return g_strdup(name);
a41c76
 }
a41c76
 
a41c76
 
a41c76
diff --git a/src/util/virhash.h b/src/util/virhash.h
a41c76
index 08f99d8a3d..cb59fb639b 100644
a41c76
--- a/src/util/virhash.h
a41c76
+++ b/src/util/virhash.h
a41c76
@@ -83,7 +83,8 @@ typedef bool (*virHashKeyEqual)(const void *namea, const void *nameb);
a41c76
  * Create a copy of the hash key, duplicating
a41c76
  * memory allocation where applicable
a41c76
  *
a41c76
- * Returns a newly allocated copy of @name
a41c76
+ * Returns a copy of @name which will eventually be passed to the
a41c76
+ * 'virHashKeyFree' callback at the end of its lifetime.
a41c76
  */
a41c76
 typedef void *(*virHashKeyCopy)(const void *name);
a41c76
 /**
a41c76
-- 
a41c76
2.25.0
a41c76