render / rpms / libvirt

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