You need to sign in or sign up before continuing.
提交 a5e89ae1 编写于 作者: P Peter Krempa

util: Make the virDomainListFree helper more universal

Extend it to a universal helper used for clearing lists of any objects.
Note that the argument type is specifically void * to allow implicit
typecasting.

Additionally add a helper that works on non-NULL terminated arrays once
we know the length.
上级 8910e063
...@@ -6382,7 +6382,7 @@ remoteDispatchConnectGetAllDomainStats(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -6382,7 +6382,7 @@ remoteDispatchConnectGetAllDomainStats(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetMessageSaveError(rerr); virNetMessageSaveError(rerr);
virDomainStatsRecordListFree(retStats); virDomainStatsRecordListFree(retStats);
virDomainListFree(doms); virObjectListFree(doms);
return rv; return rv;
} }
......
...@@ -23071,28 +23071,6 @@ virDomainListPopulate(void *payload, ...@@ -23071,28 +23071,6 @@ virDomainListPopulate(void *payload,
#undef MATCH #undef MATCH
/**
* virDomainListFree:
* @list: list of domains to free
*
* Frees a NULL-terminated list of domains without messing with currently
* set libvirt errors.
*/
void
virDomainListFree(virDomainPtr *list)
{
virDomainPtr *next;
if (!list)
return;
for (next = list; *next; next++)
virObjectUnref(*next);
VIR_FREE(list);
}
int int
virDomainObjListExport(virDomainObjListPtr doms, virDomainObjListExport(virDomainObjListPtr doms,
virConnectPtr conn, virConnectPtr conn,
...@@ -23128,7 +23106,7 @@ virDomainObjListExport(virDomainObjListPtr doms, ...@@ -23128,7 +23106,7 @@ virDomainObjListExport(virDomainObjListPtr doms,
ret = data.ndomains; ret = data.ndomains;
cleanup: cleanup:
virDomainListFree(data.domains); virObjectListFree(data.domains);
virObjectUnlock(doms); virObjectUnlock(doms);
return ret; return ret;
} }
......
...@@ -3057,8 +3057,6 @@ int virDomainObjListExport(virDomainObjListPtr doms, ...@@ -3057,8 +3057,6 @@ int virDomainObjListExport(virDomainObjListPtr doms,
virDomainObjListFilter filter, virDomainObjListFilter filter,
unsigned int flags); unsigned int flags);
void virDomainListFree(virDomainPtr *list);
int int
virDomainDefMaybeAddController(virDomainDefPtr def, virDomainDefMaybeAddController(virDomainDefPtr def,
int type, int type,
......
...@@ -341,7 +341,6 @@ virDomainLifecycleCrashTypeFromString; ...@@ -341,7 +341,6 @@ virDomainLifecycleCrashTypeFromString;
virDomainLifecycleCrashTypeToString; virDomainLifecycleCrashTypeToString;
virDomainLifecycleTypeFromString; virDomainLifecycleTypeFromString;
virDomainLifecycleTypeToString; virDomainLifecycleTypeToString;
virDomainListFree;
virDomainLiveConfigHelperMethod; virDomainLiveConfigHelperMethod;
virDomainLoaderDefFree; virDomainLoaderDefFree;
virDomainLoaderTypeFromString; virDomainLoaderTypeFromString;
...@@ -1881,6 +1880,8 @@ virClassNew; ...@@ -1881,6 +1880,8 @@ virClassNew;
virObjectFreeCallback; virObjectFreeCallback;
virObjectFreeHashData; virObjectFreeHashData;
virObjectIsClass; virObjectIsClass;
virObjectListFree;
virObjectListFreeCount;
virObjectLock; virObjectLock;
virObjectLockableNew; virObjectLockableNew;
virObjectNew; virObjectNew;
......
...@@ -19901,7 +19901,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, ...@@ -19901,7 +19901,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
virDomainObjEndAPI(&dom); virDomainObjEndAPI(&dom);
virDomainStatsRecordListFree(tmpstats); virDomainStatsRecordListFree(tmpstats);
virDomainListFree(domlist); virObjectListFree(domlist);
return ret; return ret;
} }
......
...@@ -405,3 +405,44 @@ void virObjectFreeHashData(void *opaque, const void *name ATTRIBUTE_UNUSED) ...@@ -405,3 +405,44 @@ void virObjectFreeHashData(void *opaque, const void *name ATTRIBUTE_UNUSED)
{ {
virObjectUnref(opaque); virObjectUnref(opaque);
} }
/**
* virObjectListFree:
* @list: A pointer to a NULL-terminated list of object pointers to free
*
* Unrefs all members of @list and frees the list itself.
*/
void virObjectListFree(void *list)
{
void **next;
if (!list)
return;
for (next = (void **) list; *next; next++)
virObjectUnref(*next);
VIR_FREE(list);
}
/**
* virObjectListFreeCount:
* @list: A pointer to a list of object pointers to freea
* @count: Number of elements in the list.
*
* Unrefs all members of @list and frees the list itself.
*/
void virObjectListFreeCount(void *list, size_t count)
{
size_t i;
if (!list)
return;
for (i = 0; i < count; i++)
virObjectUnref(((void **)list)[i]);
VIR_FREE(list);
}
...@@ -99,5 +99,7 @@ void virObjectLock(void *lockableobj) ...@@ -99,5 +99,7 @@ void virObjectLock(void *lockableobj)
void virObjectUnlock(void *lockableobj) void virObjectUnlock(void *lockableobj)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
void virObjectListFree(void *list);
void virObjectListFreeCount(void *list, size_t count);
#endif /* __VIR_OBJECT_H */ #endif /* __VIR_OBJECT_H */
...@@ -2193,7 +2193,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) ...@@ -2193,7 +2193,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virDomainStatsRecordListFree(records); virDomainStatsRecordListFree(records);
virDomainListFree(domlist); virObjectListFree(domlist);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册