Add helper to free a list of virDomainPtrs without raising or clearing errors. Use it in one place and prepare it for reuse. --- src/conf/domain_conf.c | 31 +++++++++++++++++++++++-------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3b295ab..e9ed3fc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20016,6 +20016,28 @@ virDomainListPopulate(void *payload, } #undef MATCH + +/** + * virDomainListFree: + * @list: list of domains to free + * + * Frees the 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, @@ -20024,7 +20046,6 @@ virDomainObjListExport(virDomainObjListPtr doms, unsigned int flags) { int ret = -1; - size_t i; struct virDomainListData data = { conn, NULL, @@ -20052,13 +20073,7 @@ virDomainObjListExport(virDomainObjListPtr doms, ret = data.ndomains; cleanup: - if (data.domains) { - int count = virHashSize(doms->objs); - for (i = 0; i < count; i++) - virObjectUnref(data.domains[i]); - } - - VIR_FREE(data.domains); + virDomainListFree(data.domains); virObjectUnlock(doms); return ret; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index aead903..a05254a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2707,6 +2707,8 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainObjListFilter filter, unsigned int flags); +void virDomainListFree(virDomainPtr *list); + int virDomainDefMaybeAddController(virDomainDefPtr def, int type, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6b9ee21..71fc063 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -311,6 +311,7 @@ virDomainLifecycleCrashTypeFromString; virDomainLifecycleCrashTypeToString; virDomainLifecycleTypeFromString; virDomainLifecycleTypeToString; +virDomainListFree; virDomainLiveConfigHelperMethod; virDomainLockFailureTypeFromString; virDomainLockFailureTypeToString; -- 2.0.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list