render / rpms / libvirt

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