1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virhash: Fix the expectations of virHashKeyEqual implementations

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>
This commit is contained in:
Peter Krempa 2020-01-31 08:34:57 +01:00
parent d69470a18a
commit 6cf3ec4428
3 changed files with 4 additions and 8 deletions

View 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;

View 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);
}

View 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);
/**