提交 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,
virNetMessageSaveError(rerr);
virDomainStatsRecordListFree(retStats);
virDomainListFree(doms);
virObjectListFree(doms);
return rv;
}
......
......@@ -23071,28 +23071,6 @@ virDomainListPopulate(void *payload,
#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
virDomainObjListExport(virDomainObjListPtr doms,
virConnectPtr conn,
......@@ -23128,7 +23106,7 @@ virDomainObjListExport(virDomainObjListPtr doms,
ret = data.ndomains;
cleanup:
virDomainListFree(data.domains);
virObjectListFree(data.domains);
virObjectUnlock(doms);
return ret;
}
......
......@@ -3057,8 +3057,6 @@ int virDomainObjListExport(virDomainObjListPtr doms,
virDomainObjListFilter filter,
unsigned int flags);
void virDomainListFree(virDomainPtr *list);
int
virDomainDefMaybeAddController(virDomainDefPtr def,
int type,
......
......@@ -341,7 +341,6 @@ virDomainLifecycleCrashTypeFromString;
virDomainLifecycleCrashTypeToString;
virDomainLifecycleTypeFromString;
virDomainLifecycleTypeToString;
virDomainListFree;
virDomainLiveConfigHelperMethod;
virDomainLoaderDefFree;
virDomainLoaderTypeFromString;
......@@ -1881,6 +1880,8 @@ virClassNew;
virObjectFreeCallback;
virObjectFreeHashData;
virObjectIsClass;
virObjectListFree;
virObjectListFreeCount;
virObjectLock;
virObjectLockableNew;
virObjectNew;
......
......@@ -19901,7 +19901,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
virDomainObjEndAPI(&dom);
virDomainStatsRecordListFree(tmpstats);
virDomainListFree(domlist);
virObjectListFree(domlist);
return ret;
}
......
......@@ -405,3 +405,44 @@ void virObjectFreeHashData(void *opaque, const void *name ATTRIBUTE_UNUSED)
{
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)
void virObjectUnlock(void *lockableobj)
ATTRIBUTE_NONNULL(1);
void virObjectListFree(void *list);
void virObjectListFreeCount(void *list, size_t count);
#endif /* __VIR_OBJECT_H */
......@@ -2193,7 +2193,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
ret = true;
cleanup:
virDomainStatsRecordListFree(records);
virDomainListFree(domlist);
virObjectListFree(domlist);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册