提交 7d9f7e17 编写于 作者: J Ján Tomko

test: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 a7fb30e3
...@@ -359,11 +359,9 @@ testBuildCapabilities(virConnectPtr conn) ...@@ -359,11 +359,9 @@ testBuildCapabilities(virConnectPtr conn)
caps->host.nsecModels = 1; caps->host.nsecModels = 1;
if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0)
goto error; goto error;
if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0) caps->host.secModels[0].model = g_strdup("testSecurity");
goto error;
if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0) caps->host.secModels[0].doi = g_strdup("");
goto error;
return caps; return caps;
...@@ -3105,8 +3103,7 @@ testDomainRenameCallback(virDomainObjPtr privdom, ...@@ -3105,8 +3103,7 @@ testDomainRenameCallback(virDomainObjPtr privdom,
return -1; return -1;
} }
if (VIR_STRDUP(new_dom_name, new_name) < 0) new_dom_name = g_strdup(new_name);
goto cleanup;
event_old = virDomainEventLifecycleNewFromObj(privdom, event_old = virDomainEventLifecycleNewFromObj(privdom,
VIR_DOMAIN_EVENT_UNDEFINED, VIR_DOMAIN_EVENT_UNDEFINED,
...@@ -3121,7 +3118,6 @@ testDomainRenameCallback(virDomainObjPtr privdom, ...@@ -3121,7 +3118,6 @@ testDomainRenameCallback(virDomainObjPtr privdom,
VIR_DOMAIN_EVENT_DEFINED_RENAMED); VIR_DOMAIN_EVENT_DEFINED_RENAMED);
ret = 0; ret = 0;
cleanup:
virObjectEventStateQueue(driver->eventState, event_old); virObjectEventStateQueue(driver->eventState, event_old);
virObjectEventStateQueue(driver->eventState, event_new); virObjectEventStateQueue(driver->eventState, event_new);
return ret; return ret;
...@@ -3692,8 +3688,7 @@ testDomainSetBlockIoTune(virDomainPtr dom, ...@@ -3692,8 +3688,7 @@ testDomainSetBlockIoTune(virDomainPtr dom,
} }
info = conf_disk->blkdeviotune; info = conf_disk->blkdeviotune;
if (VIR_STRDUP(info.group_name, conf_disk->blkdeviotune.group_name) < 0) info.group_name = g_strdup(conf_disk->blkdeviotune.group_name);
goto cleanup;
if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams, if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams,
VIR_DOMAIN_TUNABLE_BLKDEV_DISK, path) < 0) VIR_DOMAIN_TUNABLE_BLKDEV_DISK, path) < 0)
...@@ -3763,8 +3758,7 @@ testDomainSetBlockIoTune(virDomainPtr dom, ...@@ -3763,8 +3758,7 @@ testDomainSetBlockIoTune(virDomainPtr dom,
if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME)) { if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME)) {
VIR_FREE(info.group_name); VIR_FREE(info.group_name);
if (VIR_STRDUP(info.group_name, param->value.s) < 0) info.group_name = g_strdup(param->value.s);
goto cleanup;
if (virTypedParamsAddString(&eventParams, if (virTypedParamsAddString(&eventParams,
&eventNparams, &eventNparams,
&eventMaxparams, &eventMaxparams,
...@@ -3899,8 +3893,7 @@ testDomainGetBlockIoTune(virDomainPtr dom, ...@@ -3899,8 +3893,7 @@ testDomainGetBlockIoTune(virDomainPtr dom,
} }
reply = disk->blkdeviotune; reply = disk->blkdeviotune;
if (VIR_STRDUP(reply.group_name, disk->blkdeviotune.group_name) < 0) reply.group_name = g_strdup(disk->blkdeviotune.group_name);
goto cleanup;
TEST_SET_PARAM(0, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, TEST_SET_PARAM(0, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
VIR_TYPED_PARAM_ULLONG, reply.total_bytes_sec); VIR_TYPED_PARAM_ULLONG, reply.total_bytes_sec);
...@@ -4689,8 +4682,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom, ...@@ -4689,8 +4682,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
memset(errors, 0, sizeof(virDomainDiskError) * nerrors); memset(errors, 0, sizeof(virDomainDiskError) * nerrors);
for (i = 0; i < nerrors; i++) { for (i = 0; i < nerrors; i++) {
if (VIR_STRDUP(errors[i].disk, vm->def->disks[i]->dst) < 0) errors[i].disk = g_strdup(vm->def->disks[i]->dst);
goto cleanup;
errors[i].error = (i % (VIR_DOMAIN_DISK_ERROR_LAST - 1)) + 1; errors[i].error = (i % (VIR_DOMAIN_DISK_ERROR_LAST - 1)) + 1;
} }
ret = i; ret = i;
...@@ -4737,19 +4729,23 @@ testDomainGetFSInfo(virDomainPtr dom, ...@@ -4737,19 +4729,23 @@ testDomainGetFSInfo(virDomainPtr dom,
goto cleanup; goto cleanup;
if (VIR_ALLOC(info_ret[0]) < 0 || if (VIR_ALLOC(info_ret[0]) < 0 ||
VIR_ALLOC(info_ret[0]->devAlias) < 0 || VIR_ALLOC(info_ret[0]->devAlias) < 0)
VIR_STRDUP(info_ret[0]->mountpoint, "/") < 0 || goto cleanup;
VIR_STRDUP(info_ret[0]->fstype, "ext4") < 0 ||
VIR_STRDUP(info_ret[0]->devAlias[0], name) < 0 || info_ret[0]->mountpoint = g_strdup("/");
virAsprintf(&info_ret[0]->name, "%s1", name) < 0) info_ret[0]->fstype = g_strdup("ext4");
info_ret[0]->devAlias[0] = g_strdup(name);
if (virAsprintf(&info_ret[0]->name, "%s1", name) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC(info_ret[1]) < 0 || if (VIR_ALLOC(info_ret[1]) < 0 ||
VIR_ALLOC(info_ret[1]->devAlias) < 0 || VIR_ALLOC(info_ret[1]->devAlias) < 0)
VIR_STRDUP(info_ret[1]->mountpoint, "/boot") < 0 || goto cleanup;
VIR_STRDUP(info_ret[1]->fstype, "ext4") < 0 ||
VIR_STRDUP(info_ret[1]->devAlias[0], name) < 0 || info_ret[1]->mountpoint = g_strdup("/boot");
virAsprintf(&info_ret[1]->name, "%s2", name) < 0) info_ret[1]->fstype = g_strdup("ext4");
info_ret[1]->devAlias[0] = g_strdup(name);
if (virAsprintf(&info_ret[1]->name, "%s2", name) < 0)
goto cleanup; goto cleanup;
info_ret[0]->ndevAlias = info_ret[1]->ndevAlias = 1; info_ret[0]->ndevAlias = info_ret[1]->ndevAlias = 1;
...@@ -5101,12 +5097,10 @@ testDomainInterfaceAddresses(virDomainPtr dom, ...@@ -5101,12 +5097,10 @@ testDomainInterfaceAddresses(virDomainPtr dom,
if (VIR_ALLOC(iface) < 0) if (VIR_ALLOC(iface) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(iface->name, net->ifname) < 0) iface->name = g_strdup(net->ifname);
goto cleanup;
virMacAddrFormat(&net->mac, macaddr); virMacAddrFormat(&net->mac, macaddr);
if (VIR_STRDUP(iface->hwaddr, macaddr) < 0) iface->hwaddr = g_strdup(macaddr);
goto cleanup;
if (VIR_ALLOC(iface->addrs) < 0) if (VIR_ALLOC(iface->addrs) < 0)
goto cleanup; goto cleanup;
...@@ -6059,8 +6053,7 @@ testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj) ...@@ -6059,8 +6053,7 @@ testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj)
def->allocation = defaultPoolAlloc; def->allocation = defaultPoolAlloc;
def->available = defaultPoolCap - defaultPoolAlloc; def->available = defaultPoolCap - defaultPoolAlloc;
if (VIR_STRDUP(configFile, "") < 0) configFile = g_strdup("");
return -1;
virStoragePoolObjSetConfigFile(obj, configFile); virStoragePoolObjSetConfigFile(obj, configFile);
return 0; return 0;
...@@ -7025,8 +7018,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, ...@@ -7025,8 +7018,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
def->target.path, privvol->name) < 0) def->target.path, privvol->name) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || privvol->key = g_strdup(privvol->target.path);
virStoragePoolObjAddVol(obj, privvol) < 0) if (virStoragePoolObjAddVol(obj, privvol) < 0)
goto cleanup; goto cleanup;
def->allocation += privvol->target.allocation; def->allocation += privvol->target.allocation;
...@@ -7093,8 +7086,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, ...@@ -7093,8 +7086,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
def->target.path, privvol->name) < 0) def->target.path, privvol->name) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || privvol->key = g_strdup(privvol->target.path);
virStoragePoolObjAddVol(obj, privvol) < 0) if (virStoragePoolObjAddVol(obj, privvol) < 0)
goto cleanup; goto cleanup;
def->allocation += privvol->target.allocation; def->allocation += privvol->target.allocation;
...@@ -7319,12 +7312,8 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name) ...@@ -7319,12 +7312,8 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
return NULL; return NULL;
def = virNodeDeviceObjGetDef(obj); def = virNodeDeviceObjGetDef(obj);
if ((ret = virGetNodeDevice(conn, name))) { if ((ret = virGetNodeDevice(conn, name)))
if (VIR_STRDUP(ret->parentName, def->parent) < 0) { ret->parentName = g_strdup(def->parent);
virObjectUnref(ret);
ret = NULL;
}
}
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);
return ret; return ret;
...@@ -7408,20 +7397,12 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) ...@@ -7408,20 +7397,12 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
def = virNodeDeviceObjGetDef(obj); def = virNodeDeviceObjGetDef(obj);
for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next) { for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next) {
if (VIR_STRDUP(names[ncaps], names[ncaps] = g_strdup(virNodeDevCapTypeToString(caps->data.type));
virNodeDevCapTypeToString(caps->data.type)) < 0)
goto error;
ncaps++; ncaps++;
} }
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);
return ncaps; return ncaps;
error:
while (--ncaps >= 0)
VIR_FREE(names[ncaps]);
virNodeDeviceObjEndAPI(&obj);
return -1;
} }
...@@ -7459,8 +7440,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, ...@@ -7459,8 +7440,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
goto cleanup; goto cleanup;
VIR_FREE(def->name); VIR_FREE(def->name);
if (VIR_STRDUP(def->name, "scsi_host12") < 0) def->name = g_strdup("scsi_host12");
goto cleanup;
/* Find the 'scsi_host' cap and alter the host # and unique_id and /* Find the 'scsi_host' cap and alter the host # and unique_id and
* then for the 'fc_host' capability modify the wwnn/wwpn to be that * then for the 'fc_host' capability modify the wwnn/wwpn to be that
...@@ -7474,9 +7454,8 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, ...@@ -7474,9 +7454,8 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
VIR_FREE(caps->data.scsi_host.wwnn); VIR_FREE(caps->data.scsi_host.wwnn);
VIR_FREE(caps->data.scsi_host.wwpn); VIR_FREE(caps->data.scsi_host.wwpn);
if (VIR_STRDUP(caps->data.scsi_host.wwnn, wwnn) < 0 || caps->data.scsi_host.wwnn = g_strdup(wwnn);
VIR_STRDUP(caps->data.scsi_host.wwpn, wwpn) < 0) caps->data.scsi_host.wwpn = g_strdup(wwpn);
goto cleanup;
} else { } else {
/* For the "scsi_host" cap, increment our host and unique_id to /* For the "scsi_host" cap, increment our host and unique_id to
* give the appearance that something new was created - then add * give the appearance that something new was created - then add
...@@ -7547,8 +7526,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -7547,8 +7526,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
goto cleanup; goto cleanup;
VIR_FREE(dev->parentName); VIR_FREE(dev->parentName);
if (VIR_STRDUP(dev->parentName, def->parent) < 0) dev->parentName = g_strdup(def->parent);
goto cleanup;
ret = g_steal_pointer(&dev); ret = g_steal_pointer(&dev);
...@@ -7819,8 +7797,7 @@ testDomainScreenshot(virDomainPtr dom G_GNUC_UNUSED, ...@@ -7819,8 +7797,7 @@ testDomainScreenshot(virDomainPtr dom G_GNUC_UNUSED,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (VIR_STRDUP(ret, "image/png") < 0) ret = g_strdup("image/png");
return NULL;
if (virFDStreamOpenFile(st, PKGDATADIR "/test-screenshot.png", 0, 0, O_RDONLY) < 0) if (virFDStreamOpenFile(st, PKGDATADIR "/test-screenshot.png", 0, 0, O_RDONLY) < 0)
VIR_FREE(ret); VIR_FREE(ret);
...@@ -8635,9 +8612,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -8635,9 +8612,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
} }
if (!redefine) { if (!redefine) {
if (VIR_STRDUP(snap->def->parent_name, snap->def->parent_name = g_strdup(virDomainSnapshotGetCurrentName(vm->snapshots));
virDomainSnapshotGetCurrentName(vm->snapshots)) < 0)
goto cleanup;
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) && if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) &&
virDomainObjIsActive(vm)) { virDomainObjIsActive(vm)) {
...@@ -8703,11 +8678,8 @@ testDomainMomentReparentChildren(void *payload, ...@@ -8703,11 +8678,8 @@ testDomainMomentReparentChildren(void *payload,
VIR_FREE(moment->def->parent_name); VIR_FREE(moment->def->parent_name);
if (rep->parent->def && if (rep->parent->def)
VIR_STRDUP(moment->def->parent_name, rep->parent->def->name) < 0) { moment->def->parent_name = g_strdup(rep->parent->def->name);
rep->err = -1;
return 0;
}
return 0; return 0;
} }
...@@ -9098,9 +9070,8 @@ testDomainCheckpointCreateXML(virDomainPtr domain, ...@@ -9098,9 +9070,8 @@ testDomainCheckpointCreateXML(virDomainPtr domain,
current = virDomainCheckpointGetCurrent(vm->checkpoints); current = virDomainCheckpointGetCurrent(vm->checkpoints);
if (current) { if (current) {
if (!redefine && if (!redefine)
VIR_STRDUP(chk->def->parent_name, current->def->name) < 0) chk->def->parent_name = g_strdup(current->def->name);
goto cleanup;
if (update_current) if (update_current)
virDomainCheckpointSetCurrent(vm->checkpoints, NULL); virDomainCheckpointSetCurrent(vm->checkpoints, NULL);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册