CAMLlocal1 (rv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- int ids[i], r;
+ int *ids, r;
/* Some libvirt List* functions still throw exceptions if i == 0,
* so catch that and return an empty array directly. This changes
CAMLreturn (rv);
}
+ ids = malloc (sizeof (*ids) * i);
+ if (ids == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = $c_name (conn, ids, i));
- CHECK_ERROR (r == -1, \"$c_name\");
+ CHECK_ERROR_CLEANUP (r == -1, free (ids), \"$c_name\");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i)
Store_field (rv, i, Val_int (ids[i]));
+ free (ids);
CAMLreturn (rv);
"
CAMLlocal2 (rv, strv);
" . gen_unpack_args ($1) . "
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = $c_name ($1, names, i));
- CHECK_ERROR (r == -1, \"$c_name\");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), \"$c_name\");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
"
CAMLlocal1 (rv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- int ids[i], r;
+ int *ids, r;
/* Some libvirt List* functions still throw exceptions if i == 0,
* so catch that and return an empty array directly. This changes
CAMLreturn (rv);
}
+ ids = malloc (sizeof (*ids) * i);
+ if (ids == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListDomains (conn, ids, i));
- CHECK_ERROR (r == -1, "virConnectListDomains");
+ CHECK_ERROR_CLEANUP (r == -1, free (ids), "virConnectListDomains");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i)
Store_field (rv, i, Val_int (ids[i]));
+ free (ids);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListDefinedDomains (conn, names, i));
- CHECK_ERROR (r == -1, "virConnectListDefinedDomains");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedDomains");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListNetworks (conn, names, i));
- CHECK_ERROR (r == -1, "virConnectListNetworks");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListNetworks");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListDefinedNetworks (conn, names, i));
- CHECK_ERROR (r == -1, "virConnectListDefinedNetworks");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedNetworks");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListStoragePools (conn, names, i));
- CHECK_ERROR (r == -1, "virConnectListStoragePools");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListStoragePools");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virConnectPtr conn = Connect_val (connv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virConnectListDefinedStoragePools (conn, names, i));
- CHECK_ERROR (r == -1, "virConnectListDefinedStoragePools");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedStoragePools");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
CAMLlocal2 (rv, strv);
virStoragePoolPtr pool = Pool_val (poolv);
int i = Int_val (iv);
- char *names[i];
+ char **names;
int r;
/* Some libvirt List* functions still throw exceptions if i == 0,
CAMLreturn (rv);
}
+ names = malloc (sizeof (*names) * i);
+ if (names == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virStoragePoolListVolumes (pool, names, i));
- CHECK_ERROR (r == -1, "virStoragePoolListVolumes");
+ CHECK_ERROR_CLEANUP (r == -1, free (names), "virStoragePoolListVolumes");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
Store_field (rv, i, strv);
free (names[i]);
}
+ free (names);
CAMLreturn (rv);
}
int start = Int_val (startv);
int max = Int_val (maxv);
int r, i;
- unsigned long long freemems[max];
+ unsigned long long *freemems;
+
+ freemems = malloc(sizeof (*freemems) * max);
+ if (freemems == NULL)
+ caml_raise_out_of_memory ();
NONBLOCKING (r = virNodeGetCellsFreeMemory (conn, freemems, start, max));
- CHECK_ERROR (r == -1, "virNodeGetCellsFreeMemory");
+ CHECK_ERROR_CLEANUP (r == -1, free (freemems), "virNodeGetCellsFreeMemory");
rv = caml_alloc (r, 0);
for (i = 0; i < r; ++i) {
iv = caml_copy_int64 ((int64_t) freemems[i]);
Store_field (rv, i, iv);
}
+ free (freemems);
CAMLreturn (rv);
}
CAMLlocal4 (rv, v, v2, v3);
virDomainPtr dom = Domain_val (domv);
int nparams = Int_val (nparamsv);
- virSchedParameter params[nparams];
+ virSchedParameterPtr params;
int r, i;
+ params = malloc (sizeof (*params) * nparams);
+ if (params == NULL)
+ caml_raise_out_of_memory ();
+
NONBLOCKING (r = virDomainGetSchedulerParameters (dom, params, &nparams));
- CHECK_ERROR (r == -1, "virDomainGetSchedulerParameters");
+ CHECK_ERROR_CLEANUP (r == -1, free (params), "virDomainGetSchedulerParameters");
rv = caml_alloc (nparams, 0);
for (i = 0; i < nparams; ++i) {
}
Store_field (v, 1, v2);
}
+ free (params);
CAMLreturn (rv);
}
CAMLlocal1 (v);
virDomainPtr dom = Domain_val (domv);
int nparams = Wosize_val (paramsv);
- virSchedParameter params[nparams];
+ virSchedParameterPtr params;
int r, i;
char *name;
+ params = malloc (sizeof (*params) * nparams);
+ if (params == NULL)
+ caml_raise_out_of_memory ();
+
for (i = 0; i < nparams; ++i) {
v = Field (paramsv, i); /* Points to the two-element tuple. */
name = String_val (Field (v, 0));
}
NONBLOCKING (r = virDomainSetSchedulerParameters (dom, params, nparams));
+ free (params);
CHECK_ERROR (r == -1, "virDomainSetSchedulerParameters");
CAMLreturn (Val_unit);
virDomainPtr dom = Domain_val (domv);
int maxinfo = Int_val (maxinfov);
int maplen = Int_val (maplenv);
- virVcpuInfo info[maxinfo];
- unsigned char cpumaps[maxinfo * maplen];
+ virVcpuInfoPtr info;
+ unsigned char *cpumaps;
int r, i;
- memset (info, 0, sizeof (virVcpuInfo) * maxinfo);
- memset (cpumaps, 0, maxinfo * maplen);
+ info = calloc (maxinfo, sizeof (*info));
+ if (info == NULL)
+ caml_raise_out_of_memory ();
+ cpumaps = calloc (maxinfo * maplen, sizeof (*cpumaps));
+ if (cpumaps == NULL) {
+ free (info);
+ caml_raise_out_of_memory ();
+ }
NONBLOCKING (r = virDomainGetVcpus (dom, info, maxinfo, cpumaps, maplen));
- CHECK_ERROR (r == -1, "virDomainPinVcpu");
+ CHECK_ERROR_CLEANUP (r == -1, free (info); free (cpumaps), "virDomainPinVcpu");
/* Copy the virVcpuInfo structures. */
infov = caml_alloc (maxinfo, 0);
Store_field (rv, 1, infov);
Store_field (rv, 2, strv);
+ free (info);
+ free (cpumaps);
+
CAMLreturn (rv);
}