g_autofree char *vendor = NULL;
g_autofree char *product = NULL;
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ dev = g_new0(virPCIDevice, 1);
dev->address.domain = domain;
dev->address.bus = bus;
{
virPCIDevicePtr copy;
- if (VIR_ALLOC(copy) < 0)
- return NULL;
+ copy = g_new0(virPCIDevice, 1);
/* shallow copy to take care of most attributes */
*copy = *dev;
virPCIDeviceAddressPtr copyAddr;
/* make a copy to insert onto the list */
- if (VIR_ALLOC(copyAddr) < 0)
- goto cleanup;
+ copyAddr = g_new0(virPCIDeviceAddress, 1);
*copyAddr = *newDevAddr;
}
config_address = g_path_get_basename(device_path);
- if (VIR_ALLOC(bdf) < 0)
- return NULL;
+ bdf = g_new0(virPCIDeviceAddress, 1);
if (virPCIDeviceAddressParse(config_address, bdf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
size_t i;
virPerfPtr perf;
- if (VIR_ALLOC(perf) < 0)
- return NULL;
+ perf = g_new0(virPerf, 1);
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
perf->events[i].fd = -1;
if (virPipe(pipe_fd) < 0)
goto error;
- if (VIR_ALLOC(agent) < 0)
- goto error;
+ agent = g_new0(virPolkitAgent, 1);
agent->cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);
return NULL;
}
- if (VIR_ALLOC(range) < 0)
- return NULL;
+ range = g_new0(virPortAllocatorRange, 1);
range->start = start;
range->end = end;
/* Signal parent as soon as the child dies. RIP. */
flags |= SIGCHLD;
- if (VIR_ALLOC_N(stack, stacksize) < 0)
- return -1;
+ stack = g_new0(char, stacksize);
childStack = stack + stacksize;
VIR_DEBUG("Opening %s mode=0%02o", path, mode);
- if (VIR_ALLOC(entry) < 0)
- return NULL;
+ entry = g_new0(virRotatingFileWriterEntry, 1);
if ((entry->fd = open(path, O_CREAT|O_APPEND|O_WRONLY|O_CLOEXEC, mode)) < 0) {
virReportSystemError(errno,
VIR_DEBUG("Opening %s", path);
- if (VIR_ALLOC(entry) < 0)
- return NULL;
+ entry = g_new0(virRotatingFileReaderEntry, 1);
if ((entry->fd = open(path, O_RDONLY|O_CLOEXEC)) < 0) {
if (errno != ENOENT) {
{
virRotatingFileWriterPtr file;
- if (VIR_ALLOC(file) < 0)
- goto error;
+ file = g_new0(virRotatingFileWriter, 1);
file->basepath = g_strdup(path);
virRotatingFileReaderPtr file;
size_t i;
- if (VIR_ALLOC(file) < 0)
- goto error;
+ file = g_new0(virRotatingFileReader, 1);
if (maxbackup > VIR_MAX_MAX_BACKUP) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
}
file->nentries = maxbackup + 1;
- if (VIR_ALLOC_N(file->entries, file->nentries) < 0)
- goto error;
+ file->entries = g_new0(virRotatingFileReaderEntryPtr, file->nentries);
if (!(file->entries[file->nentries - 1] = virRotatingFileReaderEntryNew(path)))
goto error;
g_autofree char *model = NULL;
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ dev = g_new0(virSCSIDevice, 1);
dev->bus = bus;
dev->target = target;
{
g_autoptr(virUsedByInfo) copy = NULL;
- if (VIR_ALLOC(copy) < 0)
- return -1;
+ copy = g_new0(virUsedByInfo, 1);
copy->drvname = g_strdup(drvname);
copy->domname = g_strdup(domname);
{
g_autoptr(virSCSIVHostDevice) dev = NULL;
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ dev = g_new0(virSCSIVHostDevice, 1);
dev->name = g_strdup(name);
{
virSecurityLabelDefPtr seclabel = NULL;
- if (VIR_ALLOC(seclabel) < 0) {
- virSecurityLabelDefFree(seclabel);
- return NULL;
- }
+ seclabel = g_new0(virSecurityLabelDef, 1);
seclabel->model = g_strdup(model);
{
virSecurityDeviceLabelDefPtr seclabel = NULL;
- if (VIR_ALLOC(seclabel) < 0) {
- virSecurityDeviceLabelDefFree(seclabel);
- return NULL;
- }
+ seclabel = g_new0(virSecurityDeviceLabelDef, 1);
seclabel->model = g_strdup(model);
{
virSecurityDeviceLabelDefPtr ret;
- if (VIR_ALLOC(ret) < 0)
- return NULL;
+ ret = g_new0(virSecurityDeviceLabelDef, 1);
ret->relabel = src->relabel;
ret->labelskip = src->labelskip;
virStorageEncryptionPtr ret;
size_t i;
- if (VIR_ALLOC(ret) < 0)
- return NULL;
-
- if (VIR_ALLOC_N(ret->secrets, src->nsecrets) < 0)
- goto error;
+ ret = g_new0(virStorageEncryption, 1);
+ ret->secrets = g_new0(virStorageEncryptionSecretPtr, src->nsecrets);
ret->nsecrets = src->nsecrets;
ret->format = src->format;
virStorageEncryptionSecretPtr ret;
char *type_str = NULL;
- if (VIR_ALLOC(ret) < 0)
- return NULL;
+ ret = g_new0(virStorageEncryptionSecret, 1);
ctxt->node = node;
ctxt->node = node;
- if (VIR_ALLOC(encdef) < 0)
- goto cleanup;
+ encdef = g_new0(virStorageEncryption, 1);
if (!(format_str = virXPathString("string(./@format)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
goto cleanup;
if (n > 0) {
- if (VIR_ALLOC_N(encdef->secrets, n) < 0)
- goto cleanup;
+ encdef->secrets = g_new0(virStorageEncryptionSecretPtr, n);
encdef->nsecrets = n;
for (i = 0; i < n; i++) {
if (!src)
return 0;
- if (VIR_ALLOC_N(cap, strlen(src) + 1) < 0)
- return -1;
+ cap = g_new0(char, strlen(src) + 1);
for (i = 0; src[i]; i++) {
cap[i] = g_ascii_toupper(src[i]);
for (i = 0; i < gain; i++) {
g_autofree char *name = NULL;
- if (VIR_ALLOC(data) < 0)
- goto error;
+ data = g_new0(struct virThreadPoolWorkerData, 1);
data->pool = pool;
data->cond = priority ? &pool->prioCond : &pool->cond;
data->priority = priority;
if (minWorkers > maxWorkers)
minWorkers = maxWorkers;
- if (VIR_ALLOC(pool) < 0)
- return NULL;
+ pool = g_new0(virThreadPool, 1);
pool->jobList.tail = pool->jobList.head = NULL;
virThreadPoolExpand(pool, 1, false) < 0)
goto error;
- if (VIR_ALLOC(job) < 0)
- goto error;
+ job = g_new0(virThreadPoolJob, 1);
job->data = jobData;
job->priority = priority;
{
char *ret;
- if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
- return NULL;
+ ret = g_new0(char, VIR_TIME_STRING_BUFLEN);
if (virTimeStringNowRaw(ret) < 0) {
virReportSystemError(errno, "%s",
{
char *ret;
- if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
- return NULL;
+ ret = g_new0(char, VIR_TIME_STRING_BUFLEN);
if (virTimeStringThenRaw(when, ret) < 0) {
virReportSystemError(errno, "%s",
va_start(ap, nparams);
- if (VIR_ALLOC_N(sorted, nparams) < 0)
- goto cleanup;
+ sorted = g_new0(virTypedParameter, nparams);
/* Here we intentionally don't copy values */
memcpy(sorted, params, sizeof(*params) * nparams);
if (!src || nparams <= 0)
return 0;
- if (VIR_ALLOC_N(*dst, nparams) < 0)
- return -1;
+ *dst = g_new0(virTypedParameter, nparams);
for (i = 0; i < nparams; i++) {
ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field));
{
size_t i, n = 0;
- if (VIR_ALLOC_N(*ret, nparams) < 0)
- return -1;
+ *ret = g_new0(virTypedParameterPtr, nparams);
for (i = 0; i < nparams; i++) {
if (STREQ(params[i].field, name)) {
if (nfiltered < 0)
goto error;
- if (nfiltered &&
- VIR_ALLOC_N(*values, nfiltered) < 0)
- goto error;
+ if (nfiltered)
+ *values = g_new0(const char *, nfiltered);
for (n = 0, i = 0; i < nfiltered; i++) {
if (filtered[i]->type == VIR_TYPED_PARAM_STRING)
goto cleanup;
}
} else {
- if (VIR_ALLOC_N(*params, remote_params_len) < 0)
- goto cleanup;
+ *params = g_new0(virTypedParameter, remote_params_len);
}
*nparams = remote_params_len;
goto cleanup;
}
- if (VIR_ALLOC_N(params_val, nparams) < 0)
- goto cleanup;
+ params_val = g_new0(struct _virTypedParameterRemote, nparams);
for (i = 0, j = 0; i < nparams; ++i) {
virTypedParameterPtr param = params + i;
return NULL;
}
- if (VIR_ALLOC(ret) < 0)
- goto error;
+ ret = g_new0(virURI, 1);
ret->scheme = g_strdup(xmluri->scheme);
ret->server = g_strdup(xmluri->server);
{
virUSBDevicePtr dev;
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ dev = g_new0(virUSBDevice, 1);
dev->bus = bus;
dev->dev = devno;
offset = strlen(prefix);
- if (VIR_ALLOC_N(name, offset + i + 1))
- return NULL;
+ name = g_new0(char, offset + i + 1);
strcpy(name, prefix);
name[offset + i] = '\0';
if (val < 0)
strbuflen = 1024;
- if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
- return -1;
+ strbuf = g_new0(char, strbuflen);
/*
* From the manpage (terrifying but true):
if (val < 0)
strbuflen = 1024;
- if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
- return NULL;
+ strbuf = g_new0(char, strbuflen);
/*
* From the manpage (terrifying but true):
if (val < 0)
strbuflen = 1024;
- if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
- goto cleanup;
+ strbuf = g_new0(char, strbuflen);
while ((rc = getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) {
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
if (val < 0)
strbuflen = 1024;
- if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
- goto cleanup;
+ strbuf = g_new0(char, strbuflen);
while ((rc = getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) {
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) {
- if (VIR_ALLOC_N(*list, ret) < 0)
- return -1;
-
+ *list = g_new0(xmlNodePtr, ret);
memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr));
}
xmlXPathFreeObject(obj);
{
virXMLValidatorPtr validator = NULL;
- if (VIR_ALLOC(validator) < 0)
- return NULL;
+ validator = g_new0(virXMLValidator, 1);
validator->schemafile = g_strdup(schemafile);