[libvirt PATCH 00/12] util: use g_new0 (glib chronicles)

Ján Tomko (12): util: resctrl fix spacing in comment util: split out VIR_ALLOC calls util: resctrl: use g_new0 util: storagefile: use g_new0 util: sysinfo: use g_new0 util: command: use g_new0 util: netdev: use g_new0 util: systemd: use g_new0 util: firewall: use g_new0 util: conf: use g_new0 util: a-n: use g_new0 util: o-z: use g_new0 src/util/iohelper.c | 3 +- src/util/virarptable.c | 3 +- src/util/virauthconfig.c | 6 +-- src/util/virbitmap.c | 4 +- src/util/vircgroup.c | 7 +-- src/util/vircommand.c | 31 +++++------- src/util/virconf.c | 23 +++------ src/util/vircrypto.c | 6 +-- src/util/virdnsmasq.c | 12 ++--- src/util/virebtables.c | 3 +- src/util/virfile.c | 12 ++--- src/util/virfirewall.c | 9 ++-- src/util/virfirewalld.c | 6 +-- src/util/virfirmware.c | 6 +-- src/util/virhash.c | 8 +--- src/util/virhostcpu.c | 9 ++-- src/util/virjson.c | 15 ++---- src/util/virlockspace.c | 17 ++----- src/util/virlog.c | 5 +- src/util/virmdev.c | 6 +-- src/util/virnetdev.c | 25 ++++------ src/util/virnetdevbandwidth.c | 22 ++------- src/util/virnetdevip.c | 3 +- src/util/virnetdevmacvlan.c | 6 +-- src/util/virnetdevtap.c | 3 +- src/util/virnetdevvlan.c | 4 +- src/util/virnetdevvportprofile.c | 7 +-- src/util/virnetlink.c | 3 +- src/util/virnuma.c | 7 +-- src/util/virpci.c | 12 ++--- src/util/virperf.c | 3 +- src/util/virpolkit.c | 3 +- src/util/virportallocator.c | 3 +- src/util/virprocess.c | 3 +- src/util/virresctrl.c | 79 ++++++++++-------------------- src/util/virrotatingfile.c | 15 ++---- src/util/virscsi.c | 6 +-- src/util/virscsivhost.c | 3 +- src/util/virseclabel.c | 13 ++--- src/util/virstorageencryption.c | 16 ++----- src/util/virstoragefile.c | 82 ++++++++++---------------------- src/util/virstring.c | 3 +- src/util/virsysinfo.c | 33 +++++-------- src/util/virsystemd.c | 19 ++------ src/util/virthreadpool.c | 9 ++-- src/util/virtime.c | 6 +-- src/util/virtypedparam.c | 20 +++----- src/util/viruri.c | 3 +- src/util/virusb.c | 3 +- src/util/virutil.c | 15 ++---- src/util/virxml.c | 11 ++--- 51 files changed, 196 insertions(+), 435 deletions(-) -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virresctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index aea3fe8687..2535627d63 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1879,7 +1879,7 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) } } - /* set default free memory bandwidth to 100%*/ + /* set default free memory bandwidth to 100% */ if (info->membw_info) { if (VIR_ALLOC(ret->mem_bw) < 0) goto error; -- 2.26.2

To make the following commits simpler. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/vircommand.c | 6 ++++-- src/util/virxml.c | 10 ++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 859d6b0ce5..8060cdfada 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2636,8 +2636,10 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) VIR_FORCE_CLOSE(cmd->infd); /* clear any error so we can catch if the helper thread reports one */ cmd->has_error = 0; - if (VIR_ALLOC(cmd->asyncioThread) < 0 || - virThreadCreateFull(cmd->asyncioThread, true, + if (VIR_ALLOC(cmd->asyncioThread) < 0) + ret = -1; + + if (virThreadCreateFull(cmd->asyncioThread, true, virCommandDoAsyncIOHelper, "cmd-async-io", false, cmd) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virxml.c b/src/util/virxml.c index 5315d4ff6f..1927ff490f 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -672,12 +672,10 @@ virXPathNodeSet(const char *xpath, ret = obj->nodesetval->nodeNr; if (list != NULL && ret) { - if (VIR_ALLOC_N(*list, ret) < 0) { - ret = -1; - } else { - memcpy(*list, obj->nodesetval->nodeTab, - ret * sizeof(xmlNodePtr)); - } + if (VIR_ALLOC_N(*list, ret) < 0) + return -1; + + memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr)); } xmlXPathFreeObject(obj); return ret; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virresctrl.c | 77 ++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 2535627d63..400c8e9981 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -552,9 +552,7 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl, continue; } - if (VIR_ALLOC(i_type) < 0) - goto cleanup; - + i_type = g_new0(virResctrlInfoPerType, 1); i_type->control.scope = type; rv = virFileReadValueUint(&i_type->control.max_allocation, @@ -617,13 +615,9 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl, if (!resctrl->levels[level]) { virResctrlInfoPerTypePtr *types = NULL; - if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0) - goto cleanup; + types = g_new0(virResctrlInfoPerTypePtr, VIR_CACHE_TYPE_LAST); - if (VIR_ALLOC(resctrl->levels[level]) < 0) { - VIR_FREE(types); - goto cleanup; - } + resctrl->levels[level] = g_new0(virResctrlInfoPerLevel, 1); resctrl->levels[level]->types = types; } @@ -654,8 +648,7 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr resctrl) virResctrlInfoMemBWPtr i_membw = NULL; /* query memory bandwidth allocation info */ - if (VIR_ALLOC(i_membw) < 0) - goto cleanup; + i_membw = g_new0(virResctrlInfoMemBW, 1); rv = virFileReadValueUint(&i_membw->bandwidth_granularity, SYSFS_RESCTRL_PATH "/info/MB/bandwidth_gran"); if (rv == -2) { @@ -721,8 +714,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) size_t nfeatures = 0; virResctrlInfoMongrpPtr info_monitor = NULL; - if (VIR_ALLOC(info_monitor) < 0) - return -1; + info_monitor = g_new0(virResctrlInfoMongrp, 1); /* For now, monitor only exists in level 3 cache */ info_monitor->cache_level = 3; @@ -947,9 +939,7 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0) goto error; - if (VIR_ALLOC((*controls)[*ncontrols - 1]) < 0) - goto error; - + (*controls)[*ncontrols - 1] = g_new0(virResctrlInfoPerCache, 1); memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control)); } @@ -1004,8 +994,7 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr resctrl, for (i = 0; i < VIR_RESCTRL_MONITOR_TYPE_LAST; i++) { if (STREQ(prefix, virResctrlMonitorPrefixTypeToString(i))) { - if (VIR_ALLOC(mon) < 0) - goto cleanup; + mon = g_new0(virResctrlInfoMon, 1); mon->type = i; break; } @@ -1121,20 +1110,16 @@ virResctrlAllocGetType(virResctrlAllocPtr alloc, if (!alloc->levels[level]) { virResctrlAllocPerTypePtr *types = NULL; - if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0) - return NULL; + types = g_new0(virResctrlAllocPerTypePtr, VIR_CACHE_TYPE_LAST); - if (VIR_ALLOC(alloc->levels[level]) < 0) { - VIR_FREE(types); - return NULL; - } + alloc->levels[level] = g_new0(virResctrlAllocPerLevel, 1); alloc->levels[level]->types = types; } a_level = alloc->levels[level]; - if (!a_level->types[type] && VIR_ALLOC(a_level->types[type]) < 0) - return NULL; + if (!a_level->types[type]) + a_level->types[type] = g_new0(virResctrlAllocPerType, 1); return a_level->types[type]; } @@ -1181,8 +1166,8 @@ virResctrlAllocUpdateSize(virResctrlAllocPtr alloc, cache - a_type->nsizes + 1) < 0) return -1; - if (!a_type->sizes[cache] && VIR_ALLOC(a_type->sizes[cache]) < 0) - return -1; + if (!a_type->sizes[cache]) + a_type->sizes[cache] = g_new0(unsigned long long, 1); *(a_type->sizes[cache]) = size; @@ -1332,8 +1317,7 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc, } if (!mem_bw) { - if (VIR_ALLOC(mem_bw) < 0) - return -1; + mem_bw = g_new0(virResctrlAllocMemBW, 1); alloc->mem_bw = mem_bw; } @@ -1349,9 +1333,7 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc, return -1; } - if (VIR_ALLOC(mem_bw->bandwidths[id]) < 0) - return -1; - + mem_bw->bandwidths[id] = g_new0(unsigned int, 1); *(mem_bw->bandwidths[id]) = memory_bandwidth; return 0; } @@ -1497,10 +1479,8 @@ virResctrlAllocParseProcessMemoryBandwidth(virResctrlInfoPtr resctrl, id - alloc->mem_bw->nbandwidths + 1) < 0) { return -1; } - if (!alloc->mem_bw->bandwidths[id]) { - if (VIR_ALLOC(alloc->mem_bw->bandwidths[id]) < 0) - return -1; - } + if (!alloc->mem_bw->bandwidths[id]) + alloc->mem_bw->bandwidths[id] = g_new0(unsigned int, 1); *(alloc->mem_bw->bandwidths[id]) = bandwidth; return 0; @@ -1536,10 +1516,8 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl, return -1; } - if (!alloc->mem_bw) { - if (VIR_ALLOC(alloc->mem_bw) < 0) - return -1; - } + if (!alloc->mem_bw) + alloc->mem_bw = g_new0(virResctrlAllocMemBW, 1); tmp = strchr(line, ':'); if (!tmp) @@ -1881,16 +1859,14 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) /* set default free memory bandwidth to 100% */ if (info->membw_info) { - if (VIR_ALLOC(ret->mem_bw) < 0) - goto error; + ret->mem_bw = g_new0(virResctrlAllocMemBW, 1); if (VIR_EXPAND_N(ret->mem_bw->bandwidths, ret->mem_bw->nbandwidths, info->membw_info->max_id + 1) < 0) goto error; for (i = 0; i < ret->mem_bw->nbandwidths; i++) { - if (VIR_ALLOC(ret->mem_bw->bandwidths[i]) < 0) - goto error; + ret->mem_bw->bandwidths[i] = g_new0(unsigned int, 1); *(ret->mem_bw->bandwidths[i]) = 100; } } @@ -2171,9 +2147,8 @@ virResctrlAllocCopyMemBW(virResctrlAllocPtr dst, if (!src->mem_bw) return 0; - if (!dst->mem_bw && - VIR_ALLOC(dst->mem_bw) < 0) - return -1; + if (!dst->mem_bw) + dst->mem_bw = g_new0(virResctrlAllocMemBW, 1); dst_bw = dst->mem_bw; @@ -2185,8 +2160,7 @@ virResctrlAllocCopyMemBW(virResctrlAllocPtr dst, for (i = 0; i < src_bw->nbandwidths; i++) { if (dst_bw->bandwidths[i]) continue; - if (VIR_ALLOC(dst_bw->bandwidths[i]) < 0) - return -1; + dst_bw->bandwidths[i] = g_new0(unsigned int, 1); *dst_bw->bandwidths[i] = *src_bw->bandwidths[i]; } @@ -2736,8 +2710,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor, if (!(node_id = STRSKIP(node_id, "_"))) continue; - if (VIR_ALLOC(stat) < 0) - goto cleanup; + stat = g_new0(virResctrlMonitorStats, 1); /* The node ID number should be here, parsing it. */ if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0) -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virstoragefile.c | 82 ++++++++++++--------------------------- 1 file changed, 25 insertions(+), 57 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 459a7be5e4..82388ae544 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -520,8 +520,7 @@ qcow2GetExtensions(const char *buf, if (!backingFormat) break; - if (VIR_ALLOC_N(tmp, len + 1) < 0) - return -1; + tmp = g_new0(char, len + 1); memcpy(tmp, buf + offset, len); tmp[len] = '\0'; @@ -575,8 +574,7 @@ qcowXGetBackingStore(char **res, return BACKING_STORE_INVALID; if (offset + size > buf_size || offset + size < offset) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) - return BACKING_STORE_ERROR; + *res = g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] = '\0'; @@ -598,8 +596,7 @@ vmdk4GetBackingStore(char **res, size_t len; g_autofree char *desc = NULL; - if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0) - return BACKING_STORE_ERROR; + desc = g_new0(char, VIR_STORAGE_MAX_HEADER); *res = NULL; /* @@ -669,8 +666,7 @@ qedGetBackingStore(char **res, return BACKING_STORE_OK; if (offset + size > buf_size || offset + size < offset) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) - return BACKING_STORE_ERROR; + *res = g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] = '\0'; @@ -959,9 +955,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta, buf, len)) { int expt_fmt = fileTypeInfo[meta->format].cryptInfo[i].format; if (!meta->encryption) { - if (VIR_ALLOC(meta->encryption) < 0) - return -1; - + meta->encryption = g_new0(virStorageEncryption, 1); meta->encryption->format = expt_fmt; } else { if (meta->encryption->format != expt_fmt) { @@ -1735,8 +1729,7 @@ virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefPtr ret = NULL; size_t i; - if (VIR_ALLOC_N(ret, nhosts) < 0) - goto error; + ret = g_new0(virStorageNetHostDef, nhosts); for (i = 0; i < nhosts; i++) { virStorageNetHostDefPtr src = &hosts[i]; @@ -1750,10 +1743,6 @@ virStorageNetHostDefCopy(size_t nhosts, } return ret; - - error: - virStorageNetHostDefFree(nhosts, ret); - return NULL; } @@ -1775,8 +1764,7 @@ virStorageAuthDefCopy(const virStorageAuthDef *src) { g_autoptr(virStorageAuthDef) authdef = NULL; - if (VIR_ALLOC(authdef) < 0) - return NULL; + authdef = g_new0(virStorageAuthDef, 1); authdef->username = g_strdup(src->username); /* Not present for storage pool, but used for disk source */ @@ -1801,8 +1789,7 @@ virStorageAuthDefParse(xmlNodePtr node, ctxt->node = node; - if (VIR_ALLOC(authdef) < 0) - goto cleanup; + authdef = g_new0(virStorageAuthDef, 1); if (!(authdef->username = virXPathString("string(./@username)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1891,8 +1878,7 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) g_autofree char *path = NULL; g_autofree char *mode = NULL; - if (VIR_ALLOC(prd) < 0) - return NULL; + prd = g_new0(virStoragePRDef, 1); if (!(managed = virXPathString("string(./@managed)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -2020,8 +2006,7 @@ virStoragePRDefCopy(virStoragePRDefPtr src) virStoragePRDefPtr copy = NULL; virStoragePRDefPtr ret = NULL; - if (VIR_ALLOC(copy) < 0) - return NULL; + copy = g_new0(virStoragePRDef, 1); copy->managed = src->managed; @@ -2129,8 +2114,7 @@ virStorageSourceSeclabelsCopy(virStorageSourcePtr to, if (from->nseclabels == 0) return 0; - if (VIR_ALLOC_N(to->seclabels, from->nseclabels) < 0) - return -1; + to->seclabels = g_new0(virSecurityDeviceLabelDefPtr, from->nseclabels); to->nseclabels = from->nseclabels; for (i = 0; i < to->nseclabels; i++) { @@ -2280,8 +2264,7 @@ virStorageTimestampsCopy(const virStorageTimestamps *src) { virStorageTimestampsPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virStorageTimestamps, 1); memcpy(ret, src, sizeof(*src)); @@ -2294,8 +2277,7 @@ virStoragePermsCopy(const virStoragePerms *src) { virStoragePermsPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virStoragePerms, 1); ret->mode = src->mode; ret->uid = src->uid; @@ -2312,8 +2294,7 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) { virStorageSourcePoolDefPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virStorageSourcePoolDef, 1); ret->voltype = src->voltype; ret->pooltype = src->pooltype; @@ -2806,9 +2787,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src, return -1; } - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (!(scheme = virStringSplit(uri->scheme, "+", 2))) @@ -3001,8 +2980,8 @@ virStorageSourceParseRBDColonString(const char *rbdstr, _("duplicate 'id' found in '%s'"), src->path); return -1; } - if (VIR_ALLOC(authdef) < 0) - return -1; + + authdef = g_new0(virStorageAuthDef, 1); authdef->username = g_strdup(p + strlen("id=")); @@ -3475,8 +3454,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src, return -1; } - if (VIR_ALLOC_N(src->hosts, nservers) < 0) - return -1; + src->hosts = g_new0(virStorageNetHostDef, nservers); src->nhosts = nservers; for (i = 0; i < nservers; i++) { @@ -3513,9 +3491,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, if (!lun) lun = "0"; - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (STRNEQ_NULLABLE(transport, "tcp")) { @@ -3583,8 +3559,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src, src->path = g_strdup(export); - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (server) { @@ -3639,9 +3614,7 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src, src->path = g_strdup(vdi); - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) < 0) @@ -3676,8 +3649,7 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src, src->path = g_strdup(path); - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (server) { @@ -3738,9 +3710,7 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, if (servers) { nservers = virJSONValueArraySize(servers); - if (VIR_ALLOC_N(src->hosts, nservers) < 0) - return -1; - + src->hosts = g_new0(virStorageNetHostDef, nservers); src->nhosts = nservers; for (i = 0; i < nservers; i++) { @@ -3814,8 +3784,7 @@ virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src, src->path = g_strdup(vdisk_id); - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts = g_new0(virStorageNetHostDef, 1); src->nhosts = 1; if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, @@ -4887,8 +4856,7 @@ virStorageFileInitAs(virStorageSourcePtr src, uid_t uid, gid_t gid) { int actualType = virStorageSourceGetActualType(src); - if (VIR_ALLOC(src->drv) < 0) - return -1; + src->drv = g_new0(virStorageDriverData, 1); if (uid == (uid_t) -1) src->drv->uid = geteuid(); -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virsysinfo.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0e9b281caf..217f842a37 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -225,8 +225,7 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDefPtr *sysdef) if ((cur = strstr(base, "platform")) == NULL) return 0; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoSystemDef, 1); base = cur; /* Account for format 'platform : XXXX'*/ @@ -318,8 +317,7 @@ virSysinfoReadPPC(void) g_auto(virSysinfoDefPtr) ret = NULL; g_autofree char *outbuf = NULL; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virSysinfoDef, 1); if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -350,8 +348,7 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSystemDefPtr *sysdef) if ((cur = strstr(base, "platform")) == NULL) return 0; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoSystemDef, 1); base = cur; /* Account for format 'platform : XXXX'*/ @@ -453,8 +450,7 @@ virSysinfoReadARM(void) /* Well, we've tried. Fall back to parsing cpuinfo */ virResetLastError(); - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virSysinfoDef, 1); if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -507,8 +503,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef) int ret = -1; virSysinfoSystemDefPtr def; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoSystemDef, 1); if (!virSysinfoParseS390Line(base, "Manufacturer", &def->manufacturer)) goto cleanup; @@ -612,8 +607,7 @@ virSysinfoReadS390(void) g_auto(virSysinfoDefPtr) ret = NULL; g_autofree char *outbuf = NULL; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virSysinfoDef, 1); /* Gather info from /proc/cpuinfo */ if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { @@ -653,8 +647,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios) if ((cur = strstr(base, "BIOS Information")) == NULL) return 0; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoBIOSDef, 1); base = cur; if ((cur = strstr(base, "Vendor: ")) != NULL) { @@ -710,8 +703,7 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef) if ((cur = strstr(base, "System Information")) == NULL) return 0; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoSystemDef, 1); base = cur; if ((cur = strstr(base, "Manufacturer: ")) != NULL) { @@ -877,8 +869,7 @@ virSysinfoParseX86Chassis(const char *base, if ((cur = strstr(base, "Chassis Information")) == NULL) return 0; - if (VIR_ALLOC(def) < 0) - return ret; + def = g_new0(virSysinfoChassisDef, 1); base = cur; if ((cur = strstr(base, "Manufacturer: ")) != NULL) { @@ -968,8 +959,7 @@ virSysinfoParseOEMStrings(const char *base, if (!(cur = strstr(base, "OEM Strings"))) return 0; - if (VIR_ALLOC(strings) < 0) - return -1; + strings = g_new0(virSysinfoOEMStringsDef, 1); while ((cur = strstr(cur, "String "))) { char *eol; @@ -1237,8 +1227,7 @@ virSysinfoReadDMI(void) if (virCommandRun(cmd, NULL) < 0) return NULL; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virSysinfoDef, 1); ret->type = VIR_SYSINFO_SMBIOS; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/vircommand.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8060cdfada..6350e77523 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -935,8 +935,7 @@ virCommandNewArgs(const char *const*args) { virCommandPtr cmd; - if (VIR_ALLOC(cmd) < 0) - return NULL; + cmd = g_new0(virCommand, 1); cmd->handshakeWait[0] = -1; cmd->handshakeWait[1] = -1; @@ -2183,21 +2182,18 @@ virCommandProcessIO(virCommandPtr cmd) if (cmd->outbuf) { outfd = cmd->outfd; VIR_FREE(*cmd->outbuf); - if (VIR_ALLOC_N(*cmd->outbuf, 1) < 0) - ret = -1; + *cmd->outbuf = g_new0(char, 1); } if (cmd->errbuf) { errfd = cmd->errfd; VIR_FREE(*cmd->errbuf); - if (VIR_ALLOC_N(*cmd->errbuf, 1) < 0) - ret = -1; + *cmd->errbuf = g_new0(char, 1); } if (ret == -1) goto cleanup; ret = -1; - if (VIR_ALLOC_N(fds, 3 + virCommandGetNumSendBuffers(cmd)) < 0) - goto cleanup; + fds = g_new0(struct pollfd, 3 + virCommandGetNumSendBuffers(cmd)); for (;;) { size_t i; @@ -2636,8 +2632,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) VIR_FORCE_CLOSE(cmd->infd); /* clear any error so we can catch if the helper thread reports one */ cmd->has_error = 0; - if (VIR_ALLOC(cmd->asyncioThread) < 0) - ret = -1; + cmd->asyncioThread = g_new0(virThread, 1); if (virThreadCreateFull(cmd->asyncioThread, true, virCommandDoAsyncIOHelper, @@ -2854,10 +2849,7 @@ int virCommandHandshakeWait(virCommandPtr cmd) if (c != '1') { g_autofree char *msg = NULL; ssize_t len; - if (VIR_ALLOC_N(msg, 1024) < 0) { - VIR_FORCE_CLOSE(cmd->handshakeWait[0]); - return -1; - } + msg = g_new0(char, 1024); /* Close the handshakeNotify fd before trying to read anything * further on the handshakeWait pipe; so that a child waiting * on our acknowledgment will die rather than deadlock. */ @@ -3193,8 +3185,7 @@ virCommandRunRegex(virCommandPtr cmd, int ret = -1; /* Compile all regular expressions */ - if (VIR_ALLOC_N(reg, nregex) < 0) - return -1; + reg = g_new0(GRegex *, nregex); for (i = 0; i < nregex; i++) { g_autoptr(GError) err = NULL; @@ -3212,8 +3203,7 @@ virCommandRunRegex(virCommandPtr cmd, } /* Storage for matched variables */ - if (VIR_ALLOC_N(groups, totgroups) < 0) - goto cleanup; + groups = g_new0(char *, totgroups); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, exitstatus) < 0) @@ -3299,8 +3289,7 @@ virCommandRunNul(virCommandPtr cmd, if (n_columns == 0) return -1; - if (VIR_ALLOC_N(v, n_columns) < 0) - return -1; + v = g_new0(char *, n_columns); for (i = 0; i < n_columns; i++) v[i] = NULL; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virnetdev.c | 25 +++++++++---------------- src/util/virnetdevbandwidth.c | 22 ++++------------------ src/util/virnetdevip.c | 3 +-- src/util/virnetdevmacvlan.c | 6 ++---- src/util/virnetdevtap.c | 3 +-- src/util/virnetdevvlan.c | 4 +--- src/util/virnetdevvportprofile.c | 7 ++----- 7 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 76aeeba22a..e711a6dc8a 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1209,8 +1209,7 @@ virNetDevGetVirtualFunctions(const char *pfname, n_vfname, max_vfs) < 0) goto cleanup; - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) - goto cleanup; + *vfname = g_new0(char *, *n_vfname); for (i = 0; i < *n_vfname; i++) { g_autofree char *pciConfigAddr = NULL; @@ -2039,8 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, } if (MACStr) { - if (VIR_ALLOC(*MAC) < 0) - goto cleanup; + *MAC = g_new0(virMacAddr, 1); if (virMacAddrParse(MACStr, *MAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2051,8 +2049,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, } if (adminMACStr) { - if (VIR_ALLOC(*adminMAC) < 0) - goto cleanup; + *adminMAC = g_new0(virMacAddr, 1); if (virMacAddrParse(adminMACStr, *adminMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2064,10 +2061,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf, if (vlanTag != -1) { /* construct a simple virNetDevVlan object with a single tag */ - if (VIR_ALLOC(*vlan) < 0) - goto cleanup; - if (VIR_ALLOC((*vlan)->tag) < 0) - goto cleanup; + *vlan = g_new0(virNetDevVlan, 1); + (*vlan)->tag = g_new0(unsigned int, 1); (*vlan)->nTags = 1; (*vlan)->tag[0] = vlanTag; } @@ -2664,8 +2659,8 @@ static int virNetDevGetMcastList(const char *ifname, cur = buf; while (cur) { - if (!entry && VIR_ALLOC(entry) < 0) - return -1; + if (!entry) + entry = g_new0(virNetDevMcastEntry, 1); next = strchr(cur, '\n'); if (next) @@ -2709,8 +2704,7 @@ static int virNetDevGetMulticastTable(const char *ifname, goto cleanup; if (mcast.nentries > 0) { - if (VIR_ALLOC_N(filter->multicast.table, mcast.nentries) < 0) - goto cleanup; + filter->multicast.table = g_new0(virMacAddr, mcast.nentries); for (i = 0; i < mcast.nentries; i++) { virMacAddrSet(&filter->multicast.table[i], @@ -2733,8 +2727,7 @@ virNetDevRxFilterNew(void) { virNetDevRxFilterPtr filter; - if (VIR_ALLOC(filter) < 0) - return NULL; + filter = g_new0(virNetDevRxFilter, 1); return filter; } diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 5fd7186760..c8eb5cfc79 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -442,39 +442,25 @@ int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest, const virNetDevBandwidth *src) { - int ret = -1; - *dest = NULL; if (!src) { /* nothing to be copied */ return 0; } - if (VIR_ALLOC(*dest) < 0) - goto cleanup; + *dest = g_new0(virNetDevBandwidth, 1); if (src->in) { - if (VIR_ALLOC((*dest)->in) < 0) - goto cleanup; + (*dest)->in = g_new0(virNetDevBandwidthRate, 1); memcpy((*dest)->in, src->in, sizeof(*src->in)); } if (src->out) { - if (VIR_ALLOC((*dest)->out) < 0) { - VIR_FREE((*dest)->in); - goto cleanup; - } + (*dest)->out = g_new0(virNetDevBandwidthRate, 1); memcpy((*dest)->out, src->out, sizeof(*src->out)); } - ret = 0; - - cleanup: - if (ret < 0) { - virNetDevBandwidthFree(*dest); - *dest = NULL; - } - return ret; + return 0; } bool diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index a69567da6f..fc7808cbaa 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -180,8 +180,7 @@ virNetDevIPAddrAdd(const char *ifname, if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET && !(peer && VIR_SOCKET_ADDR_VALID(peer))) { /* compute a broadcast address if this is IPv4 */ - if (VIR_ALLOC(broadcast) < 0) - return -1; + broadcast = g_new0(virSocketAddr, 1); if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index f301a9e96c..72f0d67086 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -726,11 +726,9 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, virNetlinkCallbackDataPtr calld = NULL; if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) { - if (VIR_ALLOC(calld) < 0) - goto error; + calld = g_new0(struct virNetlinkCallbackData, 1); calld->cr_ifname = g_strdup(ifname); - if (VIR_ALLOC(calld->virtPortProfile) < 0) - goto error; + calld->virtPortProfile = g_new0(virNetDevVPortProfile, 1); memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile)); virMacAddrSet(&calld->macaddress, macaddress); calld->linkdev = g_strdup(linkdev); diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 1738f48a5f..198607b5bb 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -165,8 +165,7 @@ virNetDevTapGetRealDeviceName(char *ifname G_GNUC_UNUSED) return NULL; } - if (VIR_ALLOC_N(ret, len) < 0) - return NULL; + ret = g_new0(char, len); if (sysctl(name, 6, ret, &len, 0, 0) < 0) { virReportSystemError(errno, diff --git a/src/util/virnetdevvlan.c b/src/util/virnetdevvlan.c index 2076cc48dc..154d92497c 100644 --- a/src/util/virnetdevvlan.c +++ b/src/util/virnetdevvlan.c @@ -83,9 +83,7 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlan *src) if (!src || src->nTags == 0) return 0; - if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) - return -1; - + dst->tag = g_new0(unsigned int, src->nTags); dst->trunk = src->trunk; dst->nTags = src->nTags; dst->nativeMode = src->nativeMode; diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 5dae8aa57d..5d6c055b32 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -129,9 +129,7 @@ int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr *dst, const virNetDevVPor return 0; } - if (VIR_ALLOC(*dst) < 0) - return -1; - + *dst = g_new0(virNetDevVPortProfile, 1); memcpy(*dst, src, sizeof(*src)); return 0; } @@ -431,8 +429,7 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePtr *result, } /* at least one of the source profiles is non-empty */ - if (VIR_ALLOC(*result) < 0) - return ret; + *result = g_new0(virNetDevVPortProfile, 1); /* start with the interface's profile. There are no pointers in a * virtualPortProfile, so a shallow copy is sufficient. -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virsystemd.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 8456085476..8373ee6509 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -364,8 +364,7 @@ int virSystemdCreateMachine(const char *name, if (g_atomic_int_get(&hasCreateWithNetwork)) { g_autoptr(virError) error = NULL; - if (VIR_ALLOC(error) < 0) - return -1; + error = g_new0(virError, 1); guuid = g_variant_new_fixed_array(G_VARIANT_TYPE("y"), uuid, 16, sizeof(unsigned char)); @@ -495,8 +494,7 @@ int virSystemdTerminateMachine(const char *name) if (!(conn = virGDBusGetSystemBus())) return -1; - if (VIR_ALLOC(error) < 0) - return -1; + error = g_new0(virError, 1); /* * The systemd DBus API we're invoking has the @@ -655,14 +653,8 @@ virSystemdActivationAddFD(virSystemdActivationPtr act, virSystemdActivationEntryPtr ent = virHashLookup(act->fds, name); if (!ent) { - if (VIR_ALLOC(ent) < 0) - return -1; - - if (VIR_ALLOC_N(ent->fds, 1) < 0) { - virSystemdActivationEntryFree(ent); - return -1; - } - + ent = g_new0(virSystemdActivationEntry, 1); + ent->fds = g_new0(int, 1); ent->fds[ent->nfds++] = fd; VIR_DEBUG("Record first FD %d with name %s", fd, name); @@ -902,8 +894,7 @@ virSystemdActivationNew(virSystemdActivationMap *map, const char *fdnames; VIR_DEBUG("Activated with %d FDs", nfds); - if (VIR_ALLOC(act) < 0) - return NULL; + act = g_new0(virSystemdActivation, 1); if (!(act->fds = virHashCreate(10, virSystemdActivationEntryFree))) goto error; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virfirewall.c | 9 +++------ src/util/virfirewalld.c | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 22e717bce4..f6a8beec95 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -211,8 +211,7 @@ virFirewallGroupNew(void) { virFirewallGroupPtr group; - if (VIR_ALLOC(group) < 0) - return NULL; + group = g_new0(virFirewallGroup, 1); return group; } @@ -235,8 +234,7 @@ virFirewallPtr virFirewallNew(void) if (virFirewallInitialize() < 0) return NULL; - if (VIR_ALLOC(firewall) < 0) - return NULL; + firewall = g_new0(virFirewall, 1); return firewall; } @@ -346,8 +344,7 @@ virFirewallAddRuleFullV(virFirewallPtr firewall, group = firewall->groups[firewall->currentGroup]; - if (VIR_ALLOC(rule) < 0) - goto no_memory; + rule = g_new0(virFirewallRule, 1); rule->layer = layer; rule->queryCB = cb; diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c index a94ac7c183..3178bf4b3d 100644 --- a/src/util/virfirewalld.c +++ b/src/util/virfirewalld.c @@ -139,8 +139,7 @@ virFirewallDGetBackend(void) if (!sysbus) return -1; - if (VIR_ALLOC(error) < 0) - return -1; + error = g_new0(virError, 1); message = g_variant_new("(ss)", "org.fedoraproject.FirewallD1.config", @@ -289,8 +288,7 @@ virFirewallDApplyRule(virFirewallLayer layer, return -1; } - if (VIR_ALLOC(error) < 0) - return -1; + error = g_new0(virError, 1); message = g_variant_new("(s@as)", ipv, -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virconf.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/util/virconf.c b/src/util/virconf.c index 8575dd8849..e983a769ee 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -163,8 +163,7 @@ virConfNew(void) { virConfPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virConf, 1); ret->filename = NULL; ret->flags = 0; @@ -219,8 +218,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm) if (name) VIR_DEBUG("Add entry %s %p", name, value); - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virConfEntry, 1); ret->name = name; ret->value = value; @@ -522,11 +520,7 @@ virConfParseValue(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value")); return NULL; } - if (VIR_ALLOC(ret) < 0) { - virConfFreeList(lst); - VIR_FREE(str); - return NULL; - } + ret = g_new0(virConfValue, 1); ret->type = type; ret->l = l; ret->str = str; @@ -947,8 +941,7 @@ int virConfGetValueStringList(virConfPtr conf, } } - if (VIR_ALLOC_N(*values, len + 1) < 0) - return -1; + *values = g_new0(char *, len + 1); for (len = 0, eval = cval->list; eval; len++, eval = eval->next) (*values)[len] = g_strdup(eval->str); @@ -956,8 +949,7 @@ int virConfGetValueStringList(virConfPtr conf, case VIR_CONF_STRING: if (compatString) { - if (VIR_ALLOC_N(*values, cval->str ? 2 : 1) < 0) - return -1; + *values = g_new0(char *, cval->str ? 2 : 1); if (cval->str) (*values)[0] = g_strdup(cval->str); break; @@ -1356,10 +1348,7 @@ virConfSetValue(virConfPtr conf, } if (!cur) { - if (VIR_ALLOC(cur) < 0) { - virConfFreeValue(value); - return -1; - } + cur = g_new0(virConfEntry, 1); cur->comment = NULL; cur->name = g_strdup(setting); cur->value = value; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/iohelper.c | 3 +-- src/util/virarptable.c | 3 +-- src/util/virauthconfig.c | 6 ++---- src/util/virbitmap.c | 4 +--- src/util/vircgroup.c | 7 ++----- src/util/vircrypto.c | 6 ++---- src/util/virdnsmasq.c | 12 ++++-------- src/util/virebtables.c | 3 +-- src/util/virfile.c | 12 +++--------- src/util/virfirmware.c | 6 ++---- src/util/virhash.c | 8 ++------ src/util/virhostcpu.c | 9 +++------ src/util/virjson.c | 15 +++++---------- src/util/virlockspace.c | 17 +++++------------ src/util/virlog.c | 5 +---- src/util/virmdev.c | 6 ++---- src/util/virnetlink.c | 3 +-- src/util/virnuma.c | 7 ++----- 18 files changed, 40 insertions(+), 92 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index c3eb6f8c54..49d939d290 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -63,8 +63,7 @@ runIO(const char *path, int fd, int oflags) } 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 diff --git a/src/util/virarptable.c b/src/util/virarptable.c index c4b46604a9..01a27c0093 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -74,8 +74,7 @@ virArpTableGet(void) if (msglen < 0) return NULL; - if (VIR_ALLOC(table) < 0) - return NULL; + table = g_new0(virArpTable, 1); nh = (struct nlmsghdr*)nlData; diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 2e50609531..6b5487c4b0 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -40,8 +40,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path) { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) - goto error; + auth = g_new0(virAuthConfig, 1); auth->path = g_strdup(path); @@ -65,8 +64,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path, { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) - goto error; + auth = g_new0(virAuthConfig, 1); auth->path = g_strdup(path); diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 319bd7b7ce..4fde6f4fd2 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -704,9 +704,7 @@ virBitmapToData(virBitmapPtr bitmap, 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); diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 08758b5306..5c0543c66a 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -664,10 +664,8 @@ virCgroupNew(pid_t pid, { 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); @@ -2170,8 +2168,7 @@ virCgroupGetPercpuStats(virCgroupPtr group, 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; diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 90aed32c53..c4874550af 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -88,8 +88,7 @@ virCryptoHashString(virCryptoHash hash, 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]; @@ -167,8 +166,7 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm_t gnutls_enc_alg, * 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 diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 44aa7ad95d..9030f9218a 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -109,8 +109,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, 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); @@ -141,8 +140,7 @@ addnhostsNew(const char *name, 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; @@ -343,8 +341,7 @@ hostsfileNew(const char *name, 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; @@ -444,8 +441,7 @@ dnsmasqContextNew(const char *network_name, { dnsmasqContext *ctx; - if (VIR_ALLOC(ctx) < 0) - return NULL; + ctx = g_new0(dnsmasqContext, 1); ctx->config_dir = g_strdup(config_dir); diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 1887d718a3..b23ce21ae9 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -55,8 +55,7 @@ ebtablesContextNew(const char *driver) { ebtablesContext *ctx = NULL; - if (VIR_ALLOC(ctx) < 0) - return NULL; + ctx = g_new0(ebtablesContext, 1); ctx->chain = g_strdup_printf("libvirt_%s_FORWARD", driver); diff --git a/src/util/virfile.c b/src/util/virfile.c index e120d277d0..7d0a40b0fb 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -258,8 +258,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags) return NULL; } - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virFileWrapperFd, 1); mode = fcntl(*fd, F_GETFL); @@ -1178,11 +1177,7 @@ safezero_slow(int fd, off_t offset, off_t len) 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) @@ -3160,8 +3155,7 @@ virFileOpenTty(int *ttyprimary, char **ttyName, int rawmode) 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) diff --git a/src/util/virfirmware.c b/src/util/virfirmware.c index 513ec56621..6b8a64eafa 100644 --- a/src/util/virfirmware.c +++ b/src/util/virfirmware.c @@ -112,15 +112,13 @@ virFirmwareParseList(const char *list, } 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]); } diff --git a/src/util/virhash.c b/src/util/virhash.c index abec757d99..4b503a0313 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -271,10 +271,7 @@ virHashGrow(virHashTablePtr table, size_t size) 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++) { @@ -792,8 +789,7 @@ virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table, 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); diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 28f032b972..4ae4dca067 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -145,8 +145,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum, 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, @@ -366,8 +365,7 @@ virHostCPUParseNode(const char *node, 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); @@ -1385,8 +1383,7 @@ virHostCPUGetTscInfo(void) return NULL; } - if (VIR_ALLOC(info) < 0) - return NULL; + info = g_new0(virHostCPUTscInfo, 1); info->frequency = rc * 1000ULL; diff --git a/src/util/virjson.c b/src/util/virjson.c index a4fc9e990e..3fa9a9ca24 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -438,8 +438,7 @@ virJSONValueNewString(const char *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_strdup(data); @@ -457,8 +456,7 @@ virJSONValueNewStringLen(const char *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); @@ -472,8 +470,7 @@ virJSONValueNewNumber(const char *data) { 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); @@ -533,8 +530,7 @@ virJSONValueNewBoolean(int boolean_) { virJSONValuePtr val; - if (VIR_ALLOC(val) < 0) - return NULL; + val = g_new0(virJSONValue, 1); val->type = VIR_JSON_TYPE_BOOLEAN; val->data.boolean = boolean_; @@ -548,8 +544,7 @@ virJSONValueNewNull(void) { virJSONValuePtr val; - if (VIR_ALLOC(val) < 0) - return NULL; + val = g_new0(virJSONValue, 1); val->type = VIR_JSON_TYPE_NULL; diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 9a54192cd1..ef370936a3 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -119,8 +119,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, 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; @@ -241,8 +240,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory) 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", @@ -292,8 +290,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) 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", @@ -331,8 +328,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) 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"))) { @@ -391,10 +387,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) } 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++) { diff --git a/src/util/virlog.c b/src/util/virlog.c index 285c130d36..6b7a4512e9 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1271,10 +1271,7 @@ virLogOutputNew(virLogOutputFunc f, 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; diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 26cb8300ff..31994631ed 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -150,8 +150,7 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model) return NULL; } - if (VIR_ALLOC(dev) < 0) - return NULL; + dev = g_new0(virMediatedDevice, 1); dev->path = g_steal_pointer(&sysfspath); @@ -494,8 +493,7 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, } \ } while (0) - if (VIR_ALLOC(tmp) < 0) - return -1; + tmp = g_new0(virMediatedDeviceType, 1); tmp->id = g_path_get_basename(sysfspath); diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index ea06db51ee..fdd3a6a4d0 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -1018,8 +1018,7 @@ virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups) 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); diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 6728f62a87..5d40d13977 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -265,8 +265,7 @@ virNumaGetNodeCPUs(int node, 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); @@ -477,9 +476,7 @@ virNumaGetDistances(int 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++) { -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virpci.c | 12 ++++-------- src/util/virperf.c | 3 +-- src/util/virpolkit.c | 3 +-- src/util/virportallocator.c | 3 +-- src/util/virprocess.c | 3 +-- src/util/virrotatingfile.c | 15 +++++---------- src/util/virscsi.c | 6 ++---- src/util/virscsivhost.c | 3 +-- src/util/virseclabel.c | 13 +++---------- src/util/virstorageencryption.c | 16 +++++----------- src/util/virstring.c | 3 +-- src/util/virthreadpool.c | 9 +++------ src/util/virtime.c | 6 ++---- src/util/virtypedparam.c | 20 +++++++------------- src/util/viruri.c | 3 +-- src/util/virusb.c | 3 +-- src/util/virutil.c | 15 +++++---------- src/util/virxml.c | 7 ++----- 18 files changed, 46 insertions(+), 97 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 47c671daa0..6fa8acd246 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1372,8 +1372,7 @@ virPCIDeviceNew(unsigned int domain, 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; @@ -1422,8 +1421,7 @@ virPCIDeviceCopy(virPCIDevicePtr dev) { virPCIDevicePtr copy; - if (VIR_ALLOC(copy) < 0) - return NULL; + copy = g_new0(virPCIDevice, 1); /* shallow copy to take care of most attributes */ *copy = *dev; @@ -1871,8 +1869,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq virPCIDeviceAddressPtr copyAddr; /* make a copy to insert onto the list */ - if (VIR_ALLOC(copyAddr) < 0) - goto cleanup; + copyAddr = g_new0(virPCIDeviceAddress, 1); *copyAddr = *newDevAddr; @@ -2204,8 +2201,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link) } 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, diff --git a/src/util/virperf.c b/src/util/virperf.c index 2e95509caf..7f260d2da6 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -368,8 +368,7 @@ virPerfNew(void) 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; diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index aad924a065..1d6be443f7 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -178,8 +178,7 @@ virPolkitAgentCreate(void) 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); diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index f450740318..76c6e43726 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -102,8 +102,7 @@ virPortAllocatorRangeNew(const char *name, return NULL; } - if (VIR_ALLOC(range) < 0) - return NULL; + range = g_new0(virPortAllocatorRange, 1); range->start = start; range->end = end; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index d379f7446f..9366f0630c 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1351,8 +1351,7 @@ virProcessNamespaceAvailable(unsigned int ns) /* 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; diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c index b77e30dba7..a88c332cf4 100644 --- a/src/util/virrotatingfile.c +++ b/src/util/virrotatingfile.c @@ -105,8 +105,7 @@ virRotatingFileWriterEntryNew(const char *path, 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, @@ -148,8 +147,7 @@ virRotatingFileReaderEntryNew(const char *path) 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) { @@ -238,8 +236,7 @@ virRotatingFileWriterNew(const char *path, { virRotatingFileWriterPtr file; - if (VIR_ALLOC(file) < 0) - goto error; + file = g_new0(virRotatingFileWriter, 1); file->basepath = g_strdup(path); @@ -288,8 +285,7 @@ virRotatingFileReaderNew(const char *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, @@ -299,8 +295,7 @@ virRotatingFileReaderNew(const char *path, } 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; diff --git a/src/util/virscsi.c b/src/util/virscsi.c index e3bd81b569..4dcd68d53a 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -186,8 +186,7 @@ virSCSIDeviceNew(const char *sysfs_prefix, 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; @@ -263,8 +262,7 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, { 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); diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index be1f57c6e2..a2bf9a446f 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -250,8 +250,7 @@ virSCSIVHostDeviceNew(const char *name) { g_autoptr(virSCSIVHostDevice) dev = NULL; - if (VIR_ALLOC(dev) < 0) - return NULL; + dev = g_new0(virSCSIVHostDevice, 1); dev->name = g_strdup(name); diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c index 2141d84210..174f344a8b 100644 --- a/src/util/virseclabel.c +++ b/src/util/virseclabel.c @@ -58,10 +58,7 @@ virSecurityLabelDefNew(const char *model) { virSecurityLabelDefPtr seclabel = NULL; - if (VIR_ALLOC(seclabel) < 0) { - virSecurityLabelDefFree(seclabel); - return NULL; - } + seclabel = g_new0(virSecurityLabelDef, 1); seclabel->model = g_strdup(model); @@ -75,10 +72,7 @@ virSecurityDeviceLabelDefNew(const char *model) { virSecurityDeviceLabelDefPtr seclabel = NULL; - if (VIR_ALLOC(seclabel) < 0) { - virSecurityDeviceLabelDefFree(seclabel); - return NULL; - } + seclabel = g_new0(virSecurityDeviceLabelDef, 1); seclabel->model = g_strdup(model); @@ -91,8 +85,7 @@ virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src) { virSecurityDeviceLabelDefPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virSecurityDeviceLabelDef, 1); ret->relabel = src->relabel; ret->labelskip = src->labelskip; diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c index 76958b3876..399c6926bd 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -115,12 +115,9 @@ virStorageEncryptionCopy(const virStorageEncryption *src) 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; @@ -147,8 +144,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, virStorageEncryptionSecretPtr ret; char *type_str = NULL; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(virStorageEncryptionSecret, 1); ctxt->node = node; @@ -247,8 +243,7 @@ virStorageEncryptionParseNode(xmlNodePtr 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", @@ -268,8 +263,7 @@ virStorageEncryptionParseNode(xmlNodePtr node, 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++) { diff --git a/src/util/virstring.c b/src/util/virstring.c index de2ef964f4..5c49b56f75 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1222,8 +1222,7 @@ virStringToUpper(char **dst, const char *src) 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]); diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index ca44f55c1b..3942633431 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -188,9 +188,8 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain, bool priority) 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; @@ -232,8 +231,7 @@ virThreadPoolNewFull(size_t minWorkers, if (minWorkers > maxWorkers) minWorkers = maxWorkers; - if (VIR_ALLOC(pool) < 0) - return NULL; + pool = g_new0(virThreadPool, 1); pool->jobList.tail = pool->jobList.head = NULL; @@ -403,8 +401,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, 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; diff --git a/src/util/virtime.c b/src/util/virtime.c index 88f6f0a551..baf4ce5db7 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -257,8 +257,7 @@ char *virTimeStringNow(void) { 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", @@ -286,8 +285,7 @@ char *virTimeStringThen(unsigned long long when) { 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", diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index e4e50d837a..43af4a7c56 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -68,8 +68,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...) 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); @@ -361,8 +360,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst, 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)); @@ -399,8 +397,7 @@ virTypedParamsFilter(virTypedParameterPtr params, { 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)) { @@ -447,9 +444,8 @@ virTypedParamsGetStringList(virTypedParameterPtr params, 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) @@ -551,8 +547,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params, 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; @@ -662,8 +657,7 @@ virTypedParamsSerialize(virTypedParameterPtr params, 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; diff --git a/src/util/viruri.c b/src/util/viruri.c index dd7559662b..11753a0aef 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -157,8 +157,7 @@ virURIParse(const char *uri) 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); diff --git a/src/util/virusb.c b/src/util/virusb.c index a28604c3f4..3e7e4281a3 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -312,8 +312,7 @@ virUSBDeviceNew(unsigned int bus, { virUSBDevicePtr dev; - if (VIR_ALLOC(dev) < 0) - return NULL; + dev = g_new0(virUSBDevice, 1); dev->bus = bus; dev->dev = devno; diff --git a/src/util/virutil.c b/src/util/virutil.c index 48b38c705b..708c3cf9ef 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -447,8 +447,7 @@ char *virIndexToDiskName(int idx, const char *prefix) 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'; @@ -618,8 +617,7 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bo 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): @@ -688,8 +686,7 @@ static char *virGetGroupEnt(gid_t gid) 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): @@ -774,8 +771,7 @@ virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok) 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) @@ -856,8 +852,7 @@ virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok) 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) diff --git a/src/util/virxml.c b/src/util/virxml.c index 1927ff490f..b4d6684560 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -672,9 +672,7 @@ virXPathNodeSet(const char *xpath, 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); @@ -1237,8 +1235,7 @@ virXMLValidatorInit(const char *schemafile) { virXMLValidatorPtr validator = NULL; - if (VIR_ALLOC(validator) < 0) - return NULL; + validator = g_new0(virXMLValidator, 1); validator->schemafile = g_strdup(schemafile); -- 2.26.2

On Mon, Oct 05, 2020 at 07:48:15PM +0200, Ján Tomko wrote:
Ján Tomko (12): util: resctrl fix spacing in comment util: split out VIR_ALLOC calls util: resctrl: use g_new0 util: storagefile: use g_new0 util: sysinfo: use g_new0 util: command: use g_new0 util: netdev: use g_new0 util: systemd: use g_new0 util: firewall: use g_new0 util: conf: use g_new0 util: a-n: use g_new0 util: o-z: use g_new0 Reviewed-by: Erik Skultety <eskultet@redhat.com>
participants (2)
-
Erik Skultety
-
Ján Tomko