}
buf = base;
#else
- if (VIR_ALLOC_N(buf, buflen + alignMask) < 0)
- goto cleanup;
+ buf = g_new0(char, buflen + alignMask);
base = buf;
buf = (char *) (((intptr_t) base + alignMask) & ~alignMask);
#endif
if (msglen < 0)
return NULL;
- if (VIR_ALLOC(table) < 0)
- return NULL;
+ table = g_new0(virArpTable, 1);
nh = (struct nlmsghdr*)nlData;
{
virAuthConfigPtr auth;
- if (VIR_ALLOC(auth) < 0)
- goto error;
+ auth = g_new0(virAuthConfig, 1);
auth->path = g_strdup(path);
{
virAuthConfigPtr auth;
- if (VIR_ALLOC(auth) < 0)
- goto error;
+ auth = g_new0(virAuthConfig, 1);
auth->path = g_strdup(path);
else
len = (len + CHAR_BIT) / CHAR_BIT;
- if (VIR_ALLOC_N(*data, len) < 0)
- return -1;
-
+ *data = g_new0(unsigned char, len);
*dataLen = len;
virBitmapToDataBuf(bitmap, *data, *dataLen);
{
VIR_DEBUG("pid=%lld path=%s parent=%p controllers=%d group=%p",
(long long) pid, path, parent, controllers, group);
- *group = NULL;
- if (VIR_ALLOC((*group)) < 0)
- goto error;
+ *group = g_new0(virCgroup, 1);
if (path[0] == '/' || !parent) {
(*group)->path = g_strdup(path);
param_idx = 1;
if (guestvcpus && param_idx < nparams) {
- if (VIR_ALLOC_N(sum_cpu_time, need_cpus) < 0)
- goto cleanup;
+ sum_cpu_time = g_new0(unsigned long long, need_cpus);
if (virCgroupGetPercpuVcpuSum(group, guestvcpus, sum_cpu_time,
need_cpus, cpumap) < 0)
goto cleanup;
hashstrlen = (rc * 2) + 1;
- if (VIR_ALLOC_N(*output, hashstrlen) < 0)
- return -1;
+ *output = g_new0(char, hashstrlen);
for (i = 0; i < rc; i++) {
(*output)[i * 2] = hex[(buf[i] >> 4) & 0xf];
* data from non-padded data. Hence datalen + 1
*/
ciphertextlen = VIR_ROUND_UP(datalen + 1, 16);
- if (VIR_ALLOC_N(ciphertext, ciphertextlen) < 0)
- return -1;
+ ciphertext = g_new0(uint8_t, ciphertextlen);
memcpy(ciphertext, data, datalen);
/* Fill in the padding of the buffer with the size of the padding
goto error;
idx = addnhostsfile->nhosts;
- if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
- goto error;
+ addnhostsfile->hosts[idx].hostnames = g_new0(char *, 1);
addnhostsfile->hosts[idx].ip = g_strdup(ipstr);
dnsmasqAddnHostsfile *addnhostsfile;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- if (VIR_ALLOC(addnhostsfile) < 0)
- return NULL;
+ addnhostsfile = g_new0(dnsmasqAddnHostsfile, 1);
addnhostsfile->hosts = NULL;
addnhostsfile->nhosts = 0;
dnsmasqHostsfile *hostsfile;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- if (VIR_ALLOC(hostsfile) < 0)
- return NULL;
+ hostsfile = g_new0(dnsmasqHostsfile, 1);
hostsfile->hosts = NULL;
hostsfile->nhosts = 0;
{
dnsmasqContext *ctx;
- if (VIR_ALLOC(ctx) < 0)
- return NULL;
+ ctx = g_new0(dnsmasqContext, 1);
ctx->config_dir = g_strdup(config_dir);
{
ebtablesContext *ctx = NULL;
- if (VIR_ALLOC(ctx) < 0)
- return NULL;
+ ctx = g_new0(ebtablesContext, 1);
ctx->chain = g_strdup_printf("libvirt_%s_FORWARD", driver);
return NULL;
}
- if (VIR_ALLOC(ret) < 0)
- return NULL;
+ ret = g_new0(virFileWrapperFd, 1);
mode = fcntl(*fd, F_GETFL);
remain = len;
bytes = MIN(1024 * 1024, len);
- r = VIR_ALLOC_N(buf, bytes);
- if (r < 0) {
- errno = ENOMEM;
- return -1;
- }
+ buf = g_new0(char, bytes);
while (remain) {
if (bytes > remain)
size_t len = 64;
int rc;
- if (VIR_ALLOC_N(name, len) < 0)
- goto cleanup;
+ name = g_new0(char, len);
while ((rc = ttyname_r(secondary, name, len)) == ERANGE) {
if (VIR_RESIZE_N(name, len, len, len) < 0)
}
if (i) {
- if (VIR_ALLOC_N(*firmwares, i / 2) < 0)
- goto cleanup;
+ *firmwares = g_new0(virFirmwarePtr, i / 2);
*nfirmwares = i / 2;
for (j = 0; j < i / 2; j++) {
virFirmwarePtr *fws = *firmwares;
- if (VIR_ALLOC(fws[j]) < 0)
- goto cleanup;
+ fws[j] = g_new0(virFirmware, 1);
fws[j]->name = g_strdup(token[2 * j]);
fws[j]->nvram = g_strdup(token[2 * j + 1]);
}
if (oldtable == NULL)
return -1;
- if (VIR_ALLOC_N(table->table, size) < 0) {
- table->table = oldtable;
- return -1;
- }
+ table->table = g_new0(virHashEntryPtr, size);
table->size = size;
for (i = 0; i < oldsize; i++) {
if (numElems < 0)
return NULL;
- if (VIR_ALLOC_N(iter.sortArray, numElems + 1))
- return NULL;
+ iter.sortArray = g_new0(virHashKeyValuePair, numElems + 1);
virHashForEach(table, virHashGetKeysIterator, &iter);
cpu_times_size = sizeof(long) * cpu_times_num * CPUSTATES;
- if (VIR_ALLOC_N(cpu_times, cpu_times_num * CPUSTATES) < 0)
- goto cleanup;
+ cpu_times = g_new0(long, cpu_times_num * CPUSTATES);
if (sysctlbyname(sysctl_name, cpu_times, &cpu_times_size, NULL, 0) < 0) {
virReportSystemError(errno,
sock_max++;
/* allocate cores maps for each socket */
- if (VIR_ALLOC_N(cores_maps, sock_max) < 0)
- goto cleanup;
+ cores_maps = g_new0(virBitmapPtr, sock_max);
for (i = 0; i < sock_max; i++)
cores_maps[i] = virBitmapNew(0);
return NULL;
}
- if (VIR_ALLOC(info) < 0)
- return NULL;
+ info = g_new0(virHostCPUTscInfo, 1);
info->frequency = rc * 1000ULL;
if (!data)
return virJSONValueNewNull();
- if (VIR_ALLOC(val) < 0)
- return NULL;
+ val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_STRING;
val->data.string = g_strdup(data);
if (!data)
return virJSONValueNewNull();
- if (VIR_ALLOC(val) < 0)
- return NULL;
+ val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_STRING;
val->data.string = g_strndup(data, length);
{
virJSONValuePtr val;
- if (VIR_ALLOC(val) < 0)
- return NULL;
+ val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_NUMBER;
val->data.number = g_strdup(data);
{
virJSONValuePtr val;
- if (VIR_ALLOC(val) < 0)
- return NULL;
+ val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_BOOLEAN;
val->data.boolean = boolean_;
{
virJSONValuePtr val;
- if (VIR_ALLOC(val) < 0)
- return NULL;
+ val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_NULL;
virLockSpaceResourcePtr res;
bool shared = !!(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED);
- if (VIR_ALLOC(res) < 0)
- return NULL;
+ res = g_new0(virLockSpaceResource, 1);
res->fd = -1;
res->flags = flags;
VIR_DEBUG("directory=%s", NULLSTR(directory));
- if (VIR_ALLOC(lockspace) < 0)
- return NULL;
+ lockspace = g_new0(virLockSpace, 1);
if (virMutexInit(&lockspace->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
VIR_DEBUG("object=%p", object);
- if (VIR_ALLOC(lockspace) < 0)
- return NULL;
+ lockspace = g_new0(virLockSpace, 1);
if (virMutexInit(&lockspace->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
size_t j;
size_t m;
- if (VIR_ALLOC(res) < 0)
- goto error;
+ res = g_new0(virLockSpaceResource, 1);
res->fd = -1;
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
}
m = virJSONValueArraySize(owners);
- if (VIR_ALLOC_N(res->owners, res->nOwners) < 0) {
- virLockSpaceResourceFree(res);
- goto error;
- }
+ res->owners = g_new0(pid_t, res->nOwners);
res->nOwners = m;
for (j = 0; j < res->nOwners; j++) {
ndup = g_strdup(name);
}
- if (VIR_ALLOC(ret) < 0) {
- VIR_FREE(ndup);
- return NULL;
- }
+ ret = g_new0(virLogOutput, 1);
ret->logInitMessage = true;
ret->f = f;
return NULL;
}
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ dev = g_new0(virMediatedDevice, 1);
dev->path = g_steal_pointer(&sysfspath);
} \
} while (0)
- if (VIR_ALLOC(tmp) < 0)
- return -1;
+ tmp = g_new0(virMediatedDeviceType, 1);
tmp->id = g_path_get_basename(sysfspath);
VIR_INFO("starting netlink event service with protocol %d", protocol);
- if (VIR_ALLOC(srv) < 0)
- return -1;
+ srv = g_new0(virNetlinkEventSrvPrivate, 1);
if (virMutexInit(&srv->lock) < 0) {
VIR_FREE(srv);
return -2;
}
- if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0)
- return -1;
+ mask = g_new0(unsigned long, mask_n_bytes / sizeof(*mask));
if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) {
VIR_WARN("NUMA topology for cell %d is not available, ignoring", node);
if ((max_node = virNumaGetMaxNode()) < 0)
return -1;
- if (VIR_ALLOC_N(*distances, max_node + 1) < 0)
- return -1;
-
+ *distances = g_new0(int, max_node + 1);
*ndistances = max_node + 1;
for (i = 0; i <= max_node; i++) {