size_t i;
int count = -1;
virDomainCheckpointPtr *chks;
- virshCheckpointListPtr checkpointlist = vshMalloc(ctl,
- sizeof(*checkpointlist));
+ virshCheckpointListPtr checkpointlist = NULL;
virshCheckpointListPtr ret = NULL;
unsigned int flags = orig_flags;
+ checkpointlist = g_new0(struct virshCheckpointList, 1);
+
if (from)
count = virDomainCheckpointListAllChildren(from, &chks, flags);
else
DOMBLKSTAT_LEGACY_PRINT(3, stats.wr_bytes);
DOMBLKSTAT_LEGACY_PRINT(4, stats.errs);
} else {
- params = vshCalloc(ctl, nparams, sizeof(*params));
-
+ params = g_new0(virTypedParameter, nparams);
if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) {
vshError(ctl, _("Failed to get block stats for domain '%s' device '%s'"), name, device);
goto cleanup;
static virshDomainListPtr
virshDomainListCollect(vshControl *ctl, unsigned int flags)
{
- virshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshDomainListPtr list = g_new0(struct virshDomainList, 1);
size_t i;
int ret;
int *ids = NULL;
}
if (nids) {
- ids = vshMalloc(ctl, sizeof(int) * nids);
+ ids = g_new0(int, nids);
if ((nids = virConnectListDomains(priv->conn, ids, nids)) < 0) {
vshError(ctl, "%s", _("Failed to list active domains"));
}
if (nnames) {
- names = vshMalloc(ctl, sizeof(char *) * nnames);
+ names = g_new0(char *, nnames);
if ((nnames = virConnectListDefinedDomains(priv->conn, names,
nnames)) < 0) {
}
}
- list->domains = vshMalloc(ctl, sizeof(virDomainPtr) * (nids + nnames));
+ list->domains = g_new0(virDomainPtr, nids + nnames);
list->ndomains = 0;
/* get active domains */
goto cleanup;
}
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virDomainGetBlockIoTune(dom, disk, params, &nparams, flags) != 0) {
vshError(ctl, "%s",
}
/* now go get all the blkio parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virDomainGetBlkioParameters(dom, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get blkio parameters"));
goto cleanup;
transientjob) {
/* New API */
if (bandwidth || granularity || buf_size) {
- params = vshCalloc(ctl, 3, sizeof(*params));
+ params = g_new0(virTypedParameter, 3);
if (bandwidth) {
if (!bytes) {
/* bandwidth is ulong MiB/s, but the typed parameter is
}
/* get all interface parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virDomainGetInterfaceParameters(dom, device, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get interface parameters"));
goto cleanup;
}
if (nparams) {
- params = vshMalloc(ctl, sizeof(*params) * nparams);
+ params = g_new0(virTypedParameter, nparams);
memset(params, 0, sizeof(*params) * nparams);
if (flags || current) {
return false;
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
- cpumaps = vshMalloc(ctl, virBitmapSize(vcpus) * cpumaplen);
+ cpumaps = g_new0(unsigned char, virBitmapSize(vcpus) * cpumaplen);
if (virDomainGetVcpuPinInfo(dom, virBitmapSize(vcpus),
cpumaps, cpumaplen,
if (virDomainGetInfo(dom, &info) != 0)
return false;
- cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
+ cpuinfo = g_new0(virVcpuInfo, info.nrVirtCpu);
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
- cpumaps = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
+ cpumaps = g_new0(unsigned char, info.nrVirtCpu * cpumaplen);
if ((ncpus = virDomainGetVcpus(dom,
cpuinfo, info.nrVirtCpu,
}
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
- cpumap = vshMalloc(ctl, ncpus * cpumaplen);
+ cpumap = g_new0(unsigned char, ncpus * cpumaplen);
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
cpumaplen, flags)) >= 0) {
table = vshTableNew(_("VCPU"), _("CPU Affinity"), NULL);
flags = VIR_DOMAIN_AFFECT_CURRENT;
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
- cpumap = vshMalloc(ctl, cpumaplen);
+ cpumap = g_new0(unsigned char, cpumaplen);
if (virDomainGetEmulatorPinInfo(dom, cpumap,
cpumaplen, flags) >= 0) {
vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity"));
}
/* now go get all the memory parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virDomainGetMemoryParameters(dom, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup;
}
/* now go get all the numa parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virDomainGetNumaParameters(dom, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get numa parameters"));
goto cleanup;
goto cleanup;
}
- nodes_free = vshCalloc(ctl, nodes_cnt, sizeof(*nodes_free));
- nodes_id = vshCalloc(ctl, nodes_cnt, sizeof(*nodes_id));
+ nodes_free = g_new0(unsigned long long, nodes_cnt);
+ nodes_id = g_new0(unsigned long, nodes_cnt);
for (i = 0; i < nodes_cnt; i++) {
unsigned long id;
}
}
- pagesize = vshCalloc(ctl, nodes_cnt, sizeof(*pagesize));
+ pagesize = g_new0(unsigned int, nodes_cnt);
for (i = 0; i < nodes_cnt; i++) {
char *val = virXMLPropString(nodes[i], "size");
npages = nodes_cnt;
VIR_FREE(nodes);
} else {
- pagesize = vshMalloc(ctl, sizeof(*pagesize));
+ pagesize = g_new0(unsigned int, 1);
pagesize[0] = kibibytes;
npages = 1;
}
- counts = vshCalloc(ctl, npages, sizeof(*counts));
+ counts = g_new0(unsigned long long, npages);
nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell",
ctxt, &nodes);
}
/* page size is expected in kibibytes */
- pagesize = vshMalloc(ctl, sizeof(*pagesize));
+ pagesize = g_new0(unsigned int, 1);
pagesize[0] = kibibytes;
- counts = vshMalloc(ctl, sizeof(*counts));
+ counts = g_new0(unsigned long long, 1);
if (virNodeGetFreePages(priv->conn, 1, pagesize,
cell, 1, counts, 0) < 0)
}
memset(cpu_stats, 0, sizeof(cpu_stats));
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virNodeCPUStats, nparams);
for (i = 0; i < 2; i++) {
if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, 0) != 0) {
}
/* now go get all the memory parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virNodeMemoryStats, nparams);
if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, 0) != 0) {
vshError(ctl, "%s", _("Unable to get memory stats"));
goto cleanup;
goto error;
}
- cpus = vshCalloc(ctl, n + 1, sizeof(const char *));
+ cpus = g_new0(char *, n + 1);
for (i = 0; i < n; i++) {
/* If the user provided domain capabilities XML, we need to replace
}
/* Now go get all the memory parameters */
- params = vshCalloc(ctl, nparams, sizeof(*params));
+ params = g_new0(virTypedParameter, nparams);
if (virNodeGetMemoryParameters(priv->conn, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup;
virshInterfaceListCollect(vshControl *ctl,
unsigned int flags)
{
- virshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshInterfaceListPtr list = g_new0(struct virshInterfaceList, 1);
size_t i;
int ret;
char **activeNames = NULL;
goto cleanup;
}
if (nActiveIfaces) {
- activeNames = vshMalloc(ctl, sizeof(char *) * nActiveIfaces);
+ activeNames = g_new0(char *, nActiveIfaces);
if ((nActiveIfaces = virConnectListInterfaces(priv->conn, activeNames,
nActiveIfaces)) < 0) {
goto cleanup;
}
if (nInactiveIfaces) {
- inactiveNames = vshMalloc(ctl, sizeof(char *) * nInactiveIfaces);
+ inactiveNames = g_new0(char *, nInactiveIfaces);
if ((nInactiveIfaces =
virConnectListDefinedInterfaces(priv->conn, inactiveNames,
return list;
}
- list->ifaces = vshMalloc(ctl, sizeof(virInterfacePtr) * (nAllIfaces));
+ list->ifaces = g_new0(virInterfacePtr, nAllIfaces);
list->nifaces = 0;
/* get active interfaces */
virshNetworkListCollect(vshControl *ctl,
unsigned int flags)
{
- virshNetworkListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNetworkListPtr list = g_new0(struct virshNetworkList, 1);
size_t i;
int ret;
char **names = NULL;
if (nAllNets == 0)
return list;
- names = vshMalloc(ctl, sizeof(char *) * nAllNets);
+ names = g_new0(char *, nAllNets);
/* Retrieve a list of active network names */
if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
}
}
- list->nets = vshMalloc(ctl, sizeof(virNetworkPtr) * (nAllNets));
+ list->nets = g_new0(virNetworkPtr, nAllNets);
list->nnets = 0;
/* get active networks */
const vshCmd *cmd,
unsigned int flags)
{
- virshNetworkPortListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNetworkPortListPtr list = g_new0(struct virshNetworkPortList, 1);
int ret;
virNetworkPtr network = NULL;
bool success = false;
int ncapnames,
unsigned int flags)
{
- virshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNodeDeviceListPtr list = g_new0(struct virshNodeDeviceList, 1);
size_t i;
int ret;
virNodeDevicePtr device;
if (ndevices == 0)
return list;
- names = vshMalloc(ctl, sizeof(char *) * ndevices);
+ names = g_new0(char *, ndevices);
ndevices = virNodeListDevices(priv->conn, NULL, names, ndevices, 0);
if (ndevices < 0) {
goto cleanup;
}
- list->devices = vshMalloc(ctl, sizeof(virNodeDevicePtr) * (ndevices));
+ list->devices = g_new0(virNodeDevicePtr, ndevices);
list->ndevices = 0;
/* get the node devices */
goto cleanup;
}
- caps = vshMalloc(ctl, sizeof(char *) * ncaps);
+ caps = g_new0(char *, ncaps);
if ((ncaps = virNodeDeviceListCaps(device, caps, ncaps)) < 0) {
vshError(ctl, "%s", _("Failed to get capability names of the device"));
}
if (tree) {
- char **parents = vshMalloc(ctl, sizeof(char *) * list->ndevices);
- char **names = vshMalloc(ctl, sizeof(char *) * list->ndevices);
+ char **parents = g_new0(char *, list->ndevices);
+ char **names = g_new0(char *, list->ndevices);
struct virshNodeList arrays = { names, parents };
for (i = 0; i < list->ndevices; i++)
virshNWFilterListCollect(vshControl *ctl,
unsigned int flags)
{
- virshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNWFilterListPtr list = g_new0(struct virshNWFilterList, 1);
size_t i;
int ret;
virNWFilterPtr filter;
if (nfilters == 0)
return list;
- names = vshMalloc(ctl, sizeof(char *) * nfilters);
+ names = g_new0(char *, nfilters);
nfilters = virConnectListNWFilters(priv->conn, names, nfilters);
if (nfilters < 0) {
goto cleanup;
}
- list->filters = vshMalloc(ctl, sizeof(virNWFilterPtr) * nfilters);
+ list->filters = g_new0(virNWFilterPtr, nfilters);
list->nfilters = 0;
/* get the network filters */
virshNWFilterBindingListCollect(vshControl *ctl,
unsigned int flags)
{
- virshNWFilterBindingListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNWFilterBindingListPtr list = g_new0(struct virshNWFilterBindingList, 1);
int ret;
bool success = false;
virshControlPtr priv = ctl->privData;
virshStoragePoolListCollect(vshControl *ctl,
unsigned int flags)
{
- virshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshStoragePoolListPtr list = g_new0(struct virshStoragePoolList, 1);
size_t i;
int ret;
char **names = NULL;
if (nAllPools == 0)
return list;
- names = vshMalloc(ctl, sizeof(char *) * nAllPools);
+ names = g_new0(char *, nAllPools);
/* Retrieve a list of active storage pool names */
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
}
}
- list->pools = vshMalloc(ctl, sizeof(virStoragePoolPtr) * (nAllPools));
+ list->pools = g_new0(virStoragePoolPtr, nAllPools);
list->npools = 0;
/* get active pools */
if (!(list = virshStoragePoolListCollect(ctl, flags)))
goto cleanup;
- poolInfoTexts = vshCalloc(ctl, list->npools, sizeof(*poolInfoTexts));
+ poolInfoTexts = g_new0(struct poolInfoText, list->npools);
/* Collect the storage pool information for display */
for (i = 0; i < list->npools; i++) {
virshSecretListCollect(vshControl *ctl,
unsigned int flags)
{
- virshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshSecretListPtr list = g_new0(struct virshSecretList, 1);
size_t i;
int ret;
virSecretPtr secret;
if (nsecrets == 0)
return list;
- uuids = vshMalloc(ctl, sizeof(char *) * nsecrets);
+ uuids = g_new0(char *, nsecrets);
nsecrets = virConnectListSecrets(priv->conn, uuids, nsecrets);
if (nsecrets < 0) {
goto cleanup;
}
- list->secrets = vshMalloc(ctl, sizeof(virSecretPtr) * (nsecrets));
+ list->secrets = g_new0(virSecretPtr, nsecrets);
list->nsecrets = 0;
/* get the secrets */
bool descendants = false;
bool roots = false;
virDomainSnapshotPtr *snaps;
- virshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
+ virshSnapshotListPtr snaplist = g_new0(struct virshSnapshotList, 1);
virshSnapshotListPtr ret = NULL;
const char *fromname = NULL;
int start_index = -1;
if (!count)
goto success;
- names = vshCalloc(ctl, sizeof(*names), count);
+ names = g_new0(char *, count);
/* Now that we have a count, collect the list. */
if (from && !priv->useSnapshotOld) {
if (count < 0)
goto cleanup;
- snaplist->snaps = vshCalloc(ctl, sizeof(*snaplist->snaps), count);
+ snaplist->snaps = g_new0(struct virshSnap, count);
snaplist->nsnaps = count;
for (i = 0; i < count; i++) {
snaplist->snaps[i].snap = virDomainSnapshotLookupByName(dom,
}
}
if (!changed) {
- ret = vshMalloc(ctl, sizeof(*snaplist));
+ ret = g_new0(struct virshSnapshotList, 1);
goto cleanup;
}
while (changed && remaining) {
virStoragePoolPtr pool,
unsigned int flags)
{
- virshStorageVolListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshStorageVolListPtr list = g_new0(struct virshStorageVolList, 1);
size_t i;
char **names = NULL;
virStorageVolPtr vol = NULL;
return list;
/* Retrieve the list of volume names in the pool */
- names = vshCalloc(ctl, nvols, sizeof(*names));
+ names = g_new0(char *, nvols);
if ((nvols = virStoragePoolListVolumes(pool, names, nvols)) < 0) {
vshError(ctl, "%s", _("Failed to list storage volumes"));
goto cleanup;
}
- list->vols = vshMalloc(ctl, sizeof(virStorageVolPtr) * (nvols));
+ list->vols = g_new0(virStorageVolPtr, nvols);
list->nvols = 0;
/* get the vols */
goto cleanup;
if (list->nvols > 0)
- volInfoTexts = vshCalloc(ctl, list->nvols, sizeof(*volInfoTexts));
+ volInfoTexts = g_new0(struct volInfoText, list->nvols);
/* Collect the rest of the volume information for display */
for (i = 0; i < list->nvols; i++) {
goto syntaxError;
if (tk != VSH_TK_ARG) {
if (partial) {
- vshCmdOpt *arg = vshMalloc(ctl, sizeof(vshCmdOpt));
+ vshCmdOpt *arg = g_new0(vshCmdOpt, 1);
arg->def = opt;
arg->data = tkdata;
tkdata = NULL;
}
if (opt) {
/* save option */
- vshCmdOpt *arg = vshMalloc(ctl, sizeof(vshCmdOpt));
+ vshCmdOpt *arg = g_new0(vshCmdOpt, 1);
arg->def = opt;
arg->data = tkdata;
/* command parsed -- allocate new struct for the command */
if (cmd) {
- vshCmd *c = vshMalloc(ctl, sizeof(vshCmd));
+ vshCmd *c = g_new0(vshCmd, 1);
vshCmdOpt *tmpopt = first;
/* if we encountered --help, replace parsed command with
help = vshCmddefSearch("help");
vshCommandOptFree(first);
- first = vshMalloc(ctl, sizeof(vshCmdOpt));
+ first = g_new0(vshCmdOpt, 1);
first->def = help->opts;
first->data = g_strdup(cmd->name);
first->next = NULL;
if (partial) {
vshCmd *tmp;
- tmp = vshMalloc(ctl, sizeof(*tmp));
+ tmp = g_new0(vshCmd, 1);
tmp->opts = first;
tmp->def = cmd;
}
name_len = strlen(name);
- ret[ret_size] = vshMalloc(NULL, name_len + 3);
+ ret[ret_size] = g_new0(char, name_len + 3);
g_snprintf(ret[ret_size], name_len + 3, "--%s", name);
ret_size++;
/* Terminate the string list properly. */