提交 6cf3ec44 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 d69470a1
...@@ -988,10 +988,7 @@ virZPCIAddrKeyEqual(const void *namea, ...@@ -988,10 +988,7 @@ virZPCIAddrKeyEqual(const void *namea,
static void * static void *
virZPCIAddrKeyCopy(const void *name) virZPCIAddrKeyCopy(const void *name)
{ {
unsigned int *copy; unsigned int *copy = g_new0(unsigned int, 1);
if (VIR_ALLOC(copy) < 0)
return NULL;
*copy = *((unsigned int *)name); *copy = *((unsigned int *)name);
return (void *)copy; return (void *)copy;
......
...@@ -94,9 +94,7 @@ static bool virHashStrEqual(const void *namea, const void *nameb) ...@@ -94,9 +94,7 @@ static bool virHashStrEqual(const void *namea, const void *nameb)
static void *virHashStrCopy(const void *name) static void *virHashStrCopy(const void *name)
{ {
char *ret; return g_strdup(name);
ret = g_strdup(name);
return ret;
} }
......
...@@ -83,7 +83,8 @@ typedef bool (*virHashKeyEqual)(const void *namea, const void *nameb); ...@@ -83,7 +83,8 @@ typedef bool (*virHashKeyEqual)(const void *namea, const void *nameb);
* Create a copy of the hash key, duplicating * Create a copy of the hash key, duplicating
* memory allocation where applicable * 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); typedef void *(*virHashKeyCopy)(const void *name);
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册