int status = 0;
int n;
#ifdef HAVE_LIST_ALL_DOMAINS
- virDomainPtr *domains;
+ virDomainPtr *domains = NULL;
n = virConnectListAllDomains(conn, &domains,
VIR_CONNECT_LIST_DOMAINS_PERSISTENT);
if (n < 0) {
ERROR(PLUGIN_NAME " plugin: could not notify state of domain %s",
virDomainGetName(domains[i]));
}
+ virDomainFree(domains[i]);
}
sfree(domains);
#ifndef HAVE_LIST_ALL_DOMAINS
sfree(domids);
#else
+ for (int i = 0; i < m; ++i)
+ virDomainFree(domains_inactive[i]);
sfree(domains_inactive);
#endif
return -1;
}
#ifdef HAVE_LIST_ALL_DOMAINS
+ for (int i = 0; i < n; ++i)
+ virDomainFree(domains[i]);
sfree(domains);
+ for (int i = 0; i < m; ++i)
+ virDomainFree(domains_inactive[i]);
sfree(domains_inactive);
#else
sfree(domids);
#include "testing.h"
#include "virt.c" /* sic */
-virDomainPtr *domains;
+static virDomainPtr *domains = NULL;
+static int nr_domains = 0;
static int setup(void) {
if (virInitialize() != 0) {
}
static int teardown(void) {
- sfree(domains);
+ if (domains) {
+ for (int i = 0; i < nr_domains; ++i)
+ virDomainFree(domains[i]);
+ sfree(domains);
+ }
+ nr_domains = 0;
if (conn != NULL)
virConnectClose(conn);
#ifdef HAVE_LIST_ALL_DOMAINS
DEF_TEST(get_domain_state_notify) {
if (setup() == 0) {
- int n_domains = virConnectListAllDomains(
+ nr_domains = virConnectListAllDomains(
conn, &domains, VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT);
- if (n_domains <= 0) {
- printf("ERROR: virConnectListAllDomains: n_domains <= 0\n");
+ if (nr_domains <= 0) {
+ printf("ERROR: virConnectListAllDomains: nr_domains <= 0\n");
return -1;
}