mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
conf: use g_new0
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
7ff9f76a2e
commit
a5d88ffe0a
@ -182,8 +182,8 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
|
||||
|
||||
if ((n = virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0)
|
||||
return NULL;
|
||||
if (n && VIR_ALLOC_N(def->disks, n) < 0)
|
||||
return NULL;
|
||||
if (n)
|
||||
def->disks = g_new0(virDomainCheckpointDiskDef, n);
|
||||
def->ndisks = n;
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (virDomainCheckpointDiskDefParseXML(nodes[i], ctxt,
|
||||
|
@ -155,15 +155,10 @@ virDomainCapsCPUModelsNew(size_t nmodels)
|
||||
if (!(cpuModels = virObjectNew(virDomainCapsCPUModelsClass)))
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(cpuModels->models, nmodels) < 0)
|
||||
goto error;
|
||||
cpuModels->models = g_new0(virDomainCapsCPUModel, nmodels);
|
||||
cpuModels->nmodels_max = nmodels;
|
||||
|
||||
return cpuModels;
|
||||
|
||||
error:
|
||||
virObjectUnref(cpuModels);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2242,8 +2242,7 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
|
||||
virCheckFlags(VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX |
|
||||
VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE,
|
||||
-1);
|
||||
if (VIR_ALLOC(data) < 0)
|
||||
return -1;
|
||||
data = g_new0(virDomainQemuMonitorEventData, 1);
|
||||
data->flags = flags;
|
||||
if (event && flags != -1) {
|
||||
if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) {
|
||||
|
@ -44,8 +44,7 @@ virNWFilterBindingDefForNet(const char *vmname,
|
||||
{
|
||||
virNWFilterBindingDefPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterBindingDef, 1);
|
||||
|
||||
ret->ownername = g_strdup(vmname);
|
||||
|
||||
|
@ -121,8 +121,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
|
||||
xmlNodePtr in = NULL, out = NULL;
|
||||
char *class_id_prop = NULL;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
return ret;
|
||||
def = g_new0(virNetDevBandwidth, 1);
|
||||
|
||||
if (!node || !virXMLNodeNameEqual(node, "bandwidth")) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
@ -173,8 +172,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
|
||||
}
|
||||
|
||||
if (in) {
|
||||
if (VIR_ALLOC(def->in) < 0)
|
||||
goto cleanup;
|
||||
def->in = g_new0(virNetDevBandwidthRate, 1);
|
||||
|
||||
if (virNetDevBandwidthParseRate(in, def->in) < 0) {
|
||||
/* helper reported error for us */
|
||||
@ -189,8 +187,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
|
||||
}
|
||||
|
||||
if (out) {
|
||||
if (VIR_ALLOC(def->out) < 0)
|
||||
goto cleanup;
|
||||
def->out = g_new0(virNetDevBandwidthRate, 1);
|
||||
|
||||
if (virNetDevBandwidthParseRate(out, def->out) < 0) {
|
||||
/* helper reported error for us */
|
||||
|
@ -53,9 +53,7 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(def->tag, nTags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
def->tag = g_new0(unsigned int, nTags);
|
||||
def->nativeMode = 0;
|
||||
def->nativeTag = 0;
|
||||
for (i = 0; i < nTags; i++) {
|
||||
|
@ -39,8 +39,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
|
||||
virNetDevVPortProfilePtr virtPort = NULL;
|
||||
xmlNodePtr cur = node->children;
|
||||
|
||||
if (VIR_ALLOC(virtPort) < 0)
|
||||
return NULL;
|
||||
virtPort = g_new0(virNetDevVPortProfile, 1);
|
||||
|
||||
if ((virtPortType = virXMLPropString(node, "type")) &&
|
||||
(virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
|
||||
|
@ -44,8 +44,7 @@ virNetDevIPRouteCreate(const char *errorDetail,
|
||||
virNetDevIPRoutePtr def = NULL;
|
||||
virSocketAddr testAddr;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
return NULL;
|
||||
def = g_new0(virNetDevIPRoute, 1);
|
||||
|
||||
def->family = g_strdup(family);
|
||||
|
||||
|
@ -2069,8 +2069,7 @@ virNWFilterIncludeParse(xmlNodePtr cur)
|
||||
{
|
||||
virNWFilterIncludeDefPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterIncludeDef, 1);
|
||||
|
||||
ret->filterref = virXMLPropString(cur, "filter");
|
||||
if (!ret->filterref) {
|
||||
@ -2423,8 +2422,7 @@ virNWFilterRuleParse(xmlNodePtr node)
|
||||
xmlNodePtr cur;
|
||||
virNWFilterRuleDefPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterRuleDef, 1);
|
||||
|
||||
action = virXMLPropString(node, "action");
|
||||
direction = virXMLPropString(node, "direction");
|
||||
@ -2616,8 +2614,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
|
||||
int chain_priority;
|
||||
const char *name_prefix;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterDef, 1);
|
||||
|
||||
ret->name = virXPathString("string(./@name)", ctxt);
|
||||
if (!ret->name) {
|
||||
@ -2689,8 +2686,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
|
||||
|
||||
while (curr != NULL) {
|
||||
if (curr->type == XML_ELEMENT_NODE) {
|
||||
if (VIR_ALLOC(entry) < 0)
|
||||
goto cleanup;
|
||||
entry = g_new0(virNWFilterEntry, 1);
|
||||
|
||||
if (virXMLNodeNameEqual(curr, "rule")) {
|
||||
if (!(entry->rule = virNWFilterRuleParse(curr))) {
|
||||
|
@ -424,8 +424,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
|
||||
return -1;
|
||||
}
|
||||
/* Allocate new cb */
|
||||
if (VIR_ALLOC(cb) < 0)
|
||||
goto cleanup;
|
||||
cb = g_new0(virObjectEventCallback, 1);
|
||||
cb->conn = virObjectRef(conn);
|
||||
*callbackID = cb->callbackID = cbList->nextID++;
|
||||
cb->cb = callback;
|
||||
@ -501,10 +500,7 @@ virObjectEventQueueFree(virObjectEventQueuePtr queue)
|
||||
static virObjectEventQueuePtr
|
||||
virObjectEventQueueNew(void)
|
||||
{
|
||||
virObjectEventQueuePtr ret;
|
||||
|
||||
ignore_value(VIR_ALLOC(ret));
|
||||
return ret;
|
||||
return g_new0(virObjectEventQueue, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -566,8 +562,7 @@ virObjectEventStateNew(void)
|
||||
if (!(state = virObjectLockableNew(virObjectEventStateClass)))
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC(state->callbacks) < 0)
|
||||
goto error;
|
||||
state->callbacks = g_new0(virObjectEventCallbackList, 1);
|
||||
|
||||
if (!(state->queue = virObjectEventQueueNew()))
|
||||
goto error;
|
||||
|
@ -149,8 +149,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||
|
||||
ctxt->node = root;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
return NULL;
|
||||
def = g_new0(virSecretDef, 1);
|
||||
|
||||
prop = virXPathString("string(./@ephemeral)", ctxt);
|
||||
if (prop != NULL) {
|
||||
|
@ -367,8 +367,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
if ((n = virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0)
|
||||
goto cleanup;
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_DISKS) {
|
||||
if (n && VIR_ALLOC_N(def->disks, n) < 0)
|
||||
goto cleanup;
|
||||
if (n)
|
||||
def->disks = g_new0(virDomainSnapshotDiskDef, n);
|
||||
def->ndisks = n;
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (virDomainSnapshotDiskDefParseXML(nodes[i], ctxt, &def->disks[i],
|
||||
|
@ -255,8 +255,7 @@ static void virChrdevFDStreamCloseCb(virStreamPtr st G_GNUC_UNUSED,
|
||||
virChrdevsPtr virChrdevAlloc(void)
|
||||
{
|
||||
virChrdevsPtr devs;
|
||||
if (VIR_ALLOC(devs) < 0)
|
||||
return NULL;
|
||||
devs = g_new0(virChrdevs, 1);
|
||||
|
||||
if (virMutexInit(&devs->lock) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
@ -388,11 +387,8 @@ int virChrdevOpen(virChrdevsPtr devs,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(cbdata) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_ALLOC(ent) < 0)
|
||||
goto error;
|
||||
cbdata = g_new0(virChrdevStreamInfo, 1);
|
||||
ent = g_new0(virChrdevHashEntry, 1);
|
||||
|
||||
ent->st = st;
|
||||
ent->dev = g_strdup(path);
|
||||
|
@ -62,8 +62,7 @@ virDomainCheckpointObjListNew(void)
|
||||
{
|
||||
virDomainCheckpointObjListPtr checkpoints;
|
||||
|
||||
if (VIR_ALLOC(checkpoints) < 0)
|
||||
return NULL;
|
||||
checkpoints = g_new0(virDomainCheckpointObjList, 1);
|
||||
checkpoints->base = virDomainMomentObjListNew();
|
||||
if (!checkpoints->base) {
|
||||
VIR_FREE(checkpoints);
|
||||
@ -216,9 +215,9 @@ virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints,
|
||||
|
||||
if (!chks || count < 0)
|
||||
return count;
|
||||
if (VIR_ALLOC_N(names, count) < 0 ||
|
||||
VIR_ALLOC_N(list, count + 1) < 0)
|
||||
goto cleanup;
|
||||
|
||||
names = g_new0(char *, count);
|
||||
list = g_new0(virDomainCheckpointPtr, count + 1);
|
||||
|
||||
if (virDomainCheckpointObjListGetNames(checkpoints, from, names, count,
|
||||
flags) < 0)
|
||||
|
@ -212,8 +212,7 @@ virDomainMomentObjNew(void)
|
||||
{
|
||||
virDomainMomentObjPtr moment;
|
||||
|
||||
if (VIR_ALLOC(moment) < 0)
|
||||
return NULL;
|
||||
moment = g_new0(virDomainMomentObj, 1);
|
||||
|
||||
VIR_DEBUG("obj=%p", moment);
|
||||
|
||||
@ -275,8 +274,7 @@ virDomainMomentObjListNew(void)
|
||||
{
|
||||
virDomainMomentObjListPtr moments;
|
||||
|
||||
if (VIR_ALLOC(moments) < 0)
|
||||
return NULL;
|
||||
moments = g_new0(virDomainMomentObjList, 1);
|
||||
moments->objs = virHashCreate(50, virDomainMomentObjListDataFree);
|
||||
if (!moments->objs) {
|
||||
VIR_FREE(moments);
|
||||
|
@ -981,10 +981,7 @@ virDomainObjListCollect(virDomainObjListPtr domlist,
|
||||
|
||||
virObjectRWLockRead(domlist);
|
||||
sa_assert(domlist->objs);
|
||||
if (VIR_ALLOC_N(data.vms, virHashSize(domlist->objs)) < 0) {
|
||||
virObjectRWUnlock(domlist);
|
||||
return -1;
|
||||
}
|
||||
data.vms = g_new0(virDomainObjPtr, virHashSize(domlist->objs));
|
||||
|
||||
virHashForEach(domlist->objs, virDomainObjListCollectIterator, &data);
|
||||
virObjectRWUnlock(domlist);
|
||||
@ -1074,8 +1071,7 @@ virDomainObjListExport(virDomainObjListPtr domlist,
|
||||
return -1;
|
||||
|
||||
if (domains) {
|
||||
if (VIR_ALLOC_N(doms, nvms + 1) < 0)
|
||||
goto cleanup;
|
||||
doms = g_new0(virDomainPtr, nvms + 1);
|
||||
|
||||
for (i = 0; i < nvms; i++) {
|
||||
virDomainObjPtr vm = vms[i];
|
||||
|
@ -85,8 +85,7 @@ virDomainSnapshotObjListNew(void)
|
||||
{
|
||||
virDomainSnapshotObjListPtr snapshots;
|
||||
|
||||
if (VIR_ALLOC(snapshots) < 0)
|
||||
return NULL;
|
||||
snapshots = g_new0(virDomainSnapshotObjList, 1);
|
||||
snapshots->base = virDomainMomentObjListNew();
|
||||
if (!snapshots->base) {
|
||||
VIR_FREE(snapshots);
|
||||
@ -267,9 +266,8 @@ virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
|
||||
|
||||
if (!snaps || count < 0)
|
||||
return count;
|
||||
if (VIR_ALLOC_N(names, count) < 0 ||
|
||||
VIR_ALLOC_N(list, count + 1) < 0)
|
||||
goto cleanup;
|
||||
names = g_new0(char *, count);
|
||||
list = g_new0(virDomainSnapshotPtr, count + 1);
|
||||
|
||||
if (virDomainSnapshotObjListGetNames(snapshots, from, names, count,
|
||||
flags) < 0)
|
||||
|
@ -319,9 +319,8 @@ virInterfaceObjListExport(virConnectPtr conn,
|
||||
.nifaces = 0, .error = false };
|
||||
|
||||
virObjectRWLockRead(ifaceobjs);
|
||||
if (ifaces && VIR_ALLOC_N(data.ifaces,
|
||||
virHashSize(ifaceobjs->objsName) + 1) < 0)
|
||||
goto cleanup;
|
||||
if (ifaces)
|
||||
data.ifaces = g_new0(virInterfacePtr, virHashSize(ifaceobjs->objsName));
|
||||
|
||||
virHashForEach(ifaceobjs->objsName, virInterfaceObjListExportCallback, &data);
|
||||
|
||||
|
@ -1406,8 +1406,8 @@ virNetworkObjListExport(virConnectPtr conn,
|
||||
.nnets = 0, .error = false };
|
||||
|
||||
virObjectRWLockRead(netobjs);
|
||||
if (nets && VIR_ALLOC_N(data.nets, virHashSize(netobjs->objs) + 1) < 0)
|
||||
goto cleanup;
|
||||
if (nets)
|
||||
data.nets = g_new0(virNetworkPtr, virHashSize(netobjs->objs));
|
||||
|
||||
virHashForEach(netobjs->objs, virNetworkObjListExportCallback, &data);
|
||||
|
||||
@ -1801,8 +1801,7 @@ virNetworkObjPortListExport(virNetworkPtr net,
|
||||
if (ports) {
|
||||
*ports = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(data.ports, virHashSize(obj->ports) + 1) < 0)
|
||||
goto cleanup;
|
||||
data.ports = g_new0(virNetworkPortPtr, virHashSize(obj->ports));
|
||||
}
|
||||
|
||||
virHashForEach(obj->ports, virNetworkObjPortListExportCallback, &data);
|
||||
|
@ -95,8 +95,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
|
||||
g_autofree char *managed = NULL;
|
||||
g_autofree char *driver = NULL;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
return NULL;
|
||||
def = g_new0(virNetworkPortDef, 1);
|
||||
|
||||
uuid = virXPathString("string(./uuid)", ctxt);
|
||||
if (!uuid) {
|
||||
|
@ -930,11 +930,8 @@ virNodeDeviceObjListExport(virConnectPtr conn,
|
||||
.devices = NULL, .ndevices = 0, .error = false };
|
||||
|
||||
virObjectRWLockRead(devs);
|
||||
if (devices &&
|
||||
VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) {
|
||||
virObjectRWUnlock(devs);
|
||||
return -1;
|
||||
}
|
||||
if (devices)
|
||||
data.devices = g_new0(virNodeDevicePtr, virHashSize(devs->objs));
|
||||
|
||||
virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data);
|
||||
virObjectRWUnlock(devs);
|
||||
|
@ -51,8 +51,7 @@ virNWFilterBindingDefCopy(virNWFilterBindingDefPtr src)
|
||||
{
|
||||
virNWFilterBindingDefPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterBindingDef, 1);
|
||||
|
||||
ret->ownername = g_strdup(src->ownername);
|
||||
|
||||
@ -88,8 +87,7 @@ virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
|
||||
char *mac = NULL;
|
||||
xmlNodePtr node;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virNWFilterBindingDef, 1);
|
||||
|
||||
ret->portdevname = virXPathString("string(./portdev/@name)", ctxt);
|
||||
if (!ret->portdevname) {
|
||||
|
@ -434,10 +434,7 @@ virNWFilterBindingObjListCollect(virNWFilterBindingObjListPtr domlist,
|
||||
|
||||
virObjectRWLockRead(domlist);
|
||||
sa_assert(domlist->objs);
|
||||
if (VIR_ALLOC_N(data.bindings, virHashSize(domlist->objs)) < 0) {
|
||||
virObjectRWUnlock(domlist);
|
||||
return -1;
|
||||
}
|
||||
data.bindings = g_new0(virNWFilterBindingObjPtr, virHashSize(domlist->objs));
|
||||
|
||||
virHashForEach(domlist->objs, virNWFilterBindingObjListCollectIterator, &data);
|
||||
virObjectRWUnlock(domlist);
|
||||
@ -467,8 +464,7 @@ virNWFilterBindingObjListExport(virNWFilterBindingObjListPtr bindings,
|
||||
return -1;
|
||||
|
||||
if (bindinglist) {
|
||||
if (VIR_ALLOC_N(*bindinglist, nbindings + 1) < 0)
|
||||
goto cleanup;
|
||||
*bindinglist = g_new0(virNWFilterBindingPtr, nbindings + 1);
|
||||
|
||||
for (i = 0; i < nbindings; i++) {
|
||||
virNWFilterBindingObjPtr binding = bindingobjs[i];
|
||||
|
@ -53,8 +53,7 @@ virNWFilterObjNew(void)
|
||||
{
|
||||
virNWFilterObjPtr obj;
|
||||
|
||||
if (VIR_ALLOC(obj) < 0)
|
||||
return NULL;
|
||||
obj = g_new0(virNWFilterObj, 1);
|
||||
|
||||
if (virMutexInitRecursive(&obj->lock) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -120,8 +119,7 @@ virNWFilterObjListNew(void)
|
||||
{
|
||||
virNWFilterObjListPtr nwfilters;
|
||||
|
||||
if (VIR_ALLOC(nwfilters) < 0)
|
||||
return NULL;
|
||||
nwfilters = g_new0(virNWFilterObjList, 1);
|
||||
return nwfilters;
|
||||
}
|
||||
|
||||
@ -450,8 +448,7 @@ virNWFilterObjListExport(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(tmp_filters, nwfilters->count + 1) < 0)
|
||||
goto cleanup;
|
||||
tmp_filters = g_new0(virNWFilterPtr, nwfilters->count + 1);
|
||||
|
||||
for (i = 0; i < nwfilters->count; i++) {
|
||||
obj = nwfilters->objs[i];
|
||||
|
Loading…
Reference in New Issue
Block a user