mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-30 16:35:24 +00:00
virJSONValueNewArray: Use g_new0 to allocate and remove NULL checks from callers
Use the glib allocation function that never returns NULL and remove the now dead-code checks from all callers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3b60a0c027
commit
d69470a18a
@ -949,8 +949,8 @@ virLockDaemonPreExecRestart(const char *state_file,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(lockspaces = virJSONValueNewArray()))
|
||||
goto cleanup;
|
||||
lockspaces = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) {
|
||||
virJSONValueFree(lockspaces);
|
||||
goto cleanup;
|
||||
|
@ -619,8 +619,7 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler)
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
if (!(files = virJSONValueNewArray()))
|
||||
goto error;
|
||||
files = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(ret, "files", files) < 0) {
|
||||
virJSONValueFree(files);
|
||||
|
@ -200,11 +200,7 @@ main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(leases_array_new = virJSONValueNewArray())) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("failed to create json"));
|
||||
goto cleanup;
|
||||
}
|
||||
leases_array_new = virJSONValueNewArray();
|
||||
|
||||
if (virLeaseReadCustomLeaseFile(leases_array_new, custom_lease_file,
|
||||
delete ? ip : NULL, &server_duid) < 0)
|
||||
|
@ -1201,9 +1201,6 @@ qemuAgentMakeStringsArray(const char **strings, unsigned int len)
|
||||
size_t i;
|
||||
virJSONValuePtr ret = virJSONValueNewArray(), str;
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
str = virJSONValueNewString(strings[i]);
|
||||
if (!str)
|
||||
@ -1534,8 +1531,7 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr mon,
|
||||
*nmodified = 0;
|
||||
|
||||
/* create the key data array */
|
||||
if (!(cpus = virJSONValueNewArray()))
|
||||
goto cleanup;
|
||||
cpus = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < ninfo; i++) {
|
||||
qemuAgentCPUInfoPtr in = &info[i];
|
||||
|
@ -180,8 +180,7 @@ qemuBackupDiskPrepareOneBitmapsChain(virDomainMomentDefPtr *incremental,
|
||||
g_autoptr(virJSONValue) ret = NULL;
|
||||
size_t incridx = 0;
|
||||
|
||||
if (!(ret = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
ret = virJSONValueNewArray();
|
||||
|
||||
if (!(bitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
|
||||
backingChain,
|
||||
@ -819,8 +818,7 @@ qemuBackupBegin(virDomainObjPtr vm,
|
||||
!(incremental = qemuBackupBeginCollectIncrementalCheckpoints(vm, def->incremental)))
|
||||
goto endjob;
|
||||
|
||||
if (!(actions = virJSONValueNewArray()))
|
||||
goto endjob;
|
||||
actions = virJSONValueNewArray();
|
||||
|
||||
/* The 'chk' checkpoint must be rolled back if the transaction command
|
||||
* which creates it on disk is not executed or fails */
|
||||
|
@ -524,8 +524,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
||||
virStorageNetHostDefPtr host;
|
||||
size_t i;
|
||||
|
||||
if (!(servers = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
servers = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < src->nhosts; i++) {
|
||||
host = src->hosts + i;
|
||||
@ -590,8 +589,7 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
|
||||
virStorageNetHostDefPtr host;
|
||||
size_t i;
|
||||
|
||||
if (!(servers = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
servers = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < src->nhosts; i++) {
|
||||
host = src->hosts + i;
|
||||
@ -837,8 +835,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src,
|
||||
username = srcPriv->secinfo->s.aes.username;
|
||||
keysecret = srcPriv->secinfo->s.aes.alias;
|
||||
/* the auth modes are modelled after our old command line generator */
|
||||
if (!(authmodes = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
authmodes = virJSONValueNewArray();
|
||||
|
||||
if (!(mode = virJSONValueNewString("cephx")) ||
|
||||
virJSONValueArrayAppend(authmodes, mode) < 0)
|
||||
|
@ -1344,8 +1344,7 @@ qemuBlockJobProcessEventConcludedBackup(virQEMUDriverPtr driver,
|
||||
return;
|
||||
|
||||
if (job->data.backup.bitmap) {
|
||||
if (!(actions = virJSONValueNewArray()))
|
||||
return;
|
||||
actions = virJSONValueNewArray();
|
||||
|
||||
if (qemuMonitorTransactionBitmapRemove(actions,
|
||||
job->disk->src->nodeformat,
|
||||
|
@ -217,8 +217,7 @@ qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(arr = virJSONValueNewArray()))
|
||||
return -1;
|
||||
arr = virJSONValueNewArray();
|
||||
|
||||
if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
|
||||
n->nodeformat,
|
||||
@ -261,8 +260,7 @@ qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
|
||||
g_autoptr(GSList) relabelimages = NULL;
|
||||
GSList *next;
|
||||
|
||||
if (!(actions = virJSONValueNewArray()))
|
||||
return -1;
|
||||
actions = virJSONValueNewArray();
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
|
||||
@ -535,8 +533,7 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver,
|
||||
if ((parent = virDomainCheckpointGetCurrent(vm->checkpoints)))
|
||||
(*def)->parent.parent_name = g_strdup(parent->def->name);
|
||||
|
||||
if (!(tmpactions = virJSONValueNewArray()))
|
||||
return -1;
|
||||
tmpactions = virJSONValueNewArray();
|
||||
|
||||
if (qemuCheckpointAddActions(vm, tmpactions, parent, *def) < 0)
|
||||
return -1;
|
||||
|
@ -15639,8 +15639,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(actions = virJSONValueNewArray()))
|
||||
return -1;
|
||||
actions = virJSONValueNewArray();
|
||||
|
||||
if (blockdev &&
|
||||
!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, asyncJob)))
|
||||
|
@ -651,8 +651,7 @@ qemuFirmwareInterfaceFormat(virJSONValuePtr doc,
|
||||
g_autoptr(virJSONValue) interfacesJSON = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!(interfacesJSON = virJSONValueNewArray()))
|
||||
return -1;
|
||||
interfacesJSON = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < fw->ninterfaces; i++) {
|
||||
if (virJSONValueArrayAppendString(interfacesJSON,
|
||||
@ -799,8 +798,7 @@ qemuFirmwareTargetFormat(virJSONValuePtr doc,
|
||||
g_autoptr(virJSONValue) targetsJSON = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!(targetsJSON = virJSONValueNewArray()))
|
||||
return -1;
|
||||
targetsJSON = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < fw->ntargets; i++) {
|
||||
qemuFirmwareTargetPtr t = fw->targets[i];
|
||||
@ -816,8 +814,7 @@ qemuFirmwareTargetFormat(virJSONValuePtr doc,
|
||||
virQEMUCapsArchToString(t->architecture)) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(machines = virJSONValueNewArray()))
|
||||
return -1;
|
||||
machines = virJSONValueNewArray();
|
||||
|
||||
for (j = 0; j < t->nmachines; j++) {
|
||||
if (virJSONValueArrayAppendString(machines,
|
||||
@ -851,8 +848,7 @@ qemuFirmwareFeatureFormat(virJSONValuePtr doc,
|
||||
g_autoptr(virJSONValue) featuresJSON = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!(featuresJSON = virJSONValueNewArray()))
|
||||
return -1;
|
||||
featuresJSON = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < fw->nfeatures; i++) {
|
||||
if (virJSONValueArrayAppendString(featuresJSON,
|
||||
|
@ -785,8 +785,7 @@ qemuMigrationCapsToJSON(virBitmapPtr caps,
|
||||
qemuMigrationCapability bit;
|
||||
const char *name;
|
||||
|
||||
if (!(json = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
json = virJSONValueNewArray();
|
||||
|
||||
for (bit = 0; bit < QEMU_MIGRATION_CAP_LAST; bit++) {
|
||||
bool supported = false;
|
||||
|
@ -4800,8 +4800,7 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon,
|
||||
size_t i;
|
||||
|
||||
/* create the key data array */
|
||||
if (!(keys = virJSONValueNewArray()))
|
||||
goto cleanup;
|
||||
keys = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < nkeycodes; i++) {
|
||||
if (keycodes[i] > 0xffff) {
|
||||
|
@ -603,8 +603,7 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(services = virJSONValueNewArray()))
|
||||
goto error;
|
||||
services = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(object, "services", services) < 0) {
|
||||
virJSONValueFree(services);
|
||||
@ -622,8 +621,7 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(clients = virJSONValueNewArray()))
|
||||
goto error;
|
||||
clients = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(object, "clients", clients) < 0) {
|
||||
virJSONValueFree(clients);
|
||||
|
@ -353,8 +353,7 @@ virJSONValuePtr virNetServerServicePreExecRestart(virNetServerServicePtr svc)
|
||||
if (virJSONValueObjectAppendNumberUint(object, "nrequests_client_max", svc->nrequests_client_max) < 0)
|
||||
goto error;
|
||||
|
||||
if (!(socks = virJSONValueNewArray()))
|
||||
goto error;
|
||||
socks = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(object, "socks", socks) < 0) {
|
||||
virJSONValueFree(socks);
|
||||
|
@ -561,10 +561,7 @@ virJSONValueNewNull(void)
|
||||
virJSONValuePtr
|
||||
virJSONValueNewArray(void)
|
||||
{
|
||||
virJSONValuePtr val;
|
||||
|
||||
if (VIR_ALLOC(val) < 0)
|
||||
return NULL;
|
||||
virJSONValuePtr val = g_new0(virJSONValue, 1);
|
||||
|
||||
val->type = VIR_JSON_TYPE_ARRAY;
|
||||
|
||||
@ -1265,8 +1262,7 @@ virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap)
|
||||
virJSONValuePtr ret;
|
||||
ssize_t pos = -1;
|
||||
|
||||
if (!(ret = virJSONValueNewArray()))
|
||||
return NULL;
|
||||
ret = virJSONValueNewArray();
|
||||
|
||||
if (!bitmap)
|
||||
return ret;
|
||||
@ -1522,8 +1518,6 @@ virJSONValueCopy(const virJSONValue *in)
|
||||
break;
|
||||
case VIR_JSON_TYPE_ARRAY:
|
||||
out = virJSONValueNewArray();
|
||||
if (!out)
|
||||
return NULL;
|
||||
for (i = 0; i < in->data.array.nvalues; i++) {
|
||||
virJSONValuePtr val = NULL;
|
||||
if (!(val = virJSONValueCopy(in->data.array.values[i])))
|
||||
@ -1782,9 +1776,6 @@ virJSONParserHandleStartArray(void *ctx)
|
||||
|
||||
VIR_DEBUG("parser=%p", parser);
|
||||
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
if (virJSONParserInsertValue(parser, value) < 0) {
|
||||
virJSONValueFree(value);
|
||||
return 0;
|
||||
|
@ -443,8 +443,7 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace)
|
||||
virJSONValueObjectAppendString(object, "directory", lockspace->dir) < 0)
|
||||
goto error;
|
||||
|
||||
if (!(resources = virJSONValueNewArray()))
|
||||
goto error;
|
||||
resources = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(object, "resources", resources) < 0) {
|
||||
virJSONValueFree(resources);
|
||||
@ -479,8 +478,7 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(owners = virJSONValueNewArray()))
|
||||
goto error;
|
||||
owners = virJSONValueNewArray();
|
||||
|
||||
if (virJSONValueObjectAppend(child, "owners", owners) < 0) {
|
||||
virJSONValueFree(owners);
|
||||
|
@ -206,10 +206,11 @@ virMACMapHashDumper(void *payload,
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (!(obj = virJSONValueNewObject()) ||
|
||||
!(arr = virJSONValueNewArray()))
|
||||
if (!(obj = virJSONValueNewObject()))
|
||||
goto cleanup;
|
||||
|
||||
arr = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; macs[i]; i++) {
|
||||
virJSONValuePtr m = virJSONValueNewString(macs[i]);
|
||||
|
||||
@ -244,8 +245,7 @@ virMacMapDumpStrLocked(virMacMapPtr mgr,
|
||||
virJSONValuePtr arr;
|
||||
int ret = -1;
|
||||
|
||||
if (!(arr = virJSONValueNewArray()))
|
||||
goto cleanup;
|
||||
arr = virJSONValueNewArray();
|
||||
|
||||
if (virHashForEach(mgr->macs, virMACMapHashDumper, arr) < 0)
|
||||
goto cleanup;
|
||||
|
@ -737,8 +737,7 @@ testQemuCheckpointDeleteMerge(const void *opaque)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(actions = virJSONValueNewArray()))
|
||||
return -1;
|
||||
actions = virJSONValueNewArray();
|
||||
|
||||
if (qemuCheckpointDiscardDiskBitmaps(data->chain,
|
||||
nodedata,
|
||||
|
@ -2948,9 +2948,8 @@ testQemuMonitorJSONTransaction(const void *opaque)
|
||||
if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema)))
|
||||
return -1;
|
||||
|
||||
if (!(actions = virJSONValueNewArray()) ||
|
||||
!(mergebitmaps = virJSONValueNewArray()))
|
||||
return -1;
|
||||
actions = virJSONValueNewArray();
|
||||
mergebitmaps = virJSONValueNewArray();
|
||||
|
||||
if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(mergebitmaps, "node1", "bitmap1") < 0 ||
|
||||
qemuMonitorTransactionBitmapMergeSourceAddBitmap(mergebitmaps, "node2", "bitmap2") < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user