]> xenbits.xensource.com Git - libvirt.git/commitdiff
virhash: Fix the expectations of virHashKeyEqual implementations
authorPeter Krempa <pkrempa@redhat.com>
Fri, 31 Jan 2020 07:34:57 +0000 (08:34 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 4 Feb 2020 12:45:33 +0000 (13:45 +0100)
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>
src/conf/domain_addr.c
src/util/virhash.c
src/util/virhash.h

index c0e468122a4d7a84d7aad0147bab17850bc4faac..e8629b3ed8fd668be8f577412d833fb676de5924 100644 (file)
@@ -988,10 +988,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;
index d5c5e017a14f988f50c4b0b34dc7cd71195186c8..c57d9f8292de695224ced5307673cd7a26d0d6a8 100644 (file)
@@ -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);
 }
 
 
index 08f99d8a3d063d90e63d33f1c5508ead27e51ed9..cb59fb639ba0c855530d62215257a7ed794693f2 100644 (file)
@@ -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);
 /**