---
src/test/test_driver.c | 144 ++++++++++++++++++-------------------------------
1 file changed, 52 insertions(+), 92 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index f60f106..32b200c 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -219,18 +219,17 @@ testBuildCapabilities(virConnectPtr conn) {
caps->host.nsecModels = 1;
if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0)
goto no_memory;
- caps->host.secModels[0].model = strdup("testSecurity");
- if (!caps->host.secModels[0].model)
- goto no_memory;
+ if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0)
+ goto error;
- caps->host.secModels[0].doi = strdup("");
- if (!caps->host.secModels[0].doi)
- goto no_memory;
+ if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0)
+ goto error;
return caps;
no_memory:
virReportOOMError();
+error:
virObjectUnref(caps);
return NULL;
}
@@ -673,10 +672,14 @@ static char *testBuildFilename(const char *relativeTo,
const char *filename) {
char *offset;
int baseLen;
+ char *ret;
+
if (!filename || filename[0] == '\0')
return NULL;
- if (filename[0] == '/')
- return strdup(filename);
+ if (filename[0] == '/') {
+ ignore_value(VIR_STRDUP(ret, filename));
+ return ret;
+ }
offset = strrchr(relativeTo, '/');
if ((baseLen = (offset-relativeTo+1))) {
@@ -691,7 +694,8 @@ static char *testBuildFilename(const char *relativeTo,
strcat(absFile, filename);
return absFile;
} else {
- return strdup(filename);
+ ignore_value(VIR_STRDUP(ret, filename));
+ return ret;
}
}
@@ -754,13 +758,8 @@ static int testOpenVolumesForPool(xmlDocPtr xml,
}
}
- if (def->key == NULL) {
- def->key = strdup(def->target.path);
- if (def->key == NULL) {
- virReportOOMError();
- goto error;
- }
- }
+ if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0)
+ goto error;
pool->def->allocation += def->allocation;
pool->def->available = (pool->def->capacity -
@@ -826,10 +825,8 @@ static int testOpenFromFile(virConnectPtr conn,
privconn->nextDomID = 1;
privconn->numCells = 0;
- if ((privconn->path = strdup(file)) == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(privconn->path, file) < 0)
goto error;
- }
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo;
@@ -2060,9 +2057,9 @@ cleanup:
}
static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
- char *ret = strdup("linux");
- if (!ret)
- virReportOOMError();
+ char *ret;
+
+ ignore_value(VIR_STRDUP_QUIET(ret, "linux"));
return ret;
}
@@ -2720,9 +2717,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain
ATTRIBUTE_UNUSED,
if (nparams)
*nparams = 1;
- type = strdup("fair");
- if (!type)
- virReportOOMError();
+ ignore_value(VIR_STRDUP_QUIET(type, "fair"));
return type;
}
@@ -3020,9 +3015,9 @@ static int testConnectListNetworks(virConnectPtr conn, char **const
names, int n
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]);
if (virNetworkObjIsActive(privconn->networks.objs[i]) &&
- !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
+ VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) <
0) {
virNetworkObjUnlock(privconn->networks.objs[i]);
- goto no_memory;
+ goto error;
}
virNetworkObjUnlock(privconn->networks.objs[i]);
}
@@ -3030,8 +3025,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const
names, int n
return n;
-no_memory:
- virReportOOMError();
+error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
@@ -3063,9 +3057,9 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char
**const names
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]);
if (!virNetworkObjIsActive(privconn->networks.objs[i]) &&
- !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
+ VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) <
0) {
virNetworkObjUnlock(privconn->networks.objs[i]);
- goto no_memory;
+ goto error;
}
virNetworkObjUnlock(privconn->networks.objs[i]);
}
@@ -3073,8 +3067,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char
**const names
return n;
-no_memory:
- virReportOOMError();
+error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
@@ -3381,10 +3374,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
goto cleanup;
}
- if (!(bridge = strdup(privnet->def->bridge))) {
- virReportOOMError();
- goto cleanup;
- }
+ ignore_value(VIR_STRDUP(bridge, privnet->def->bridge));
cleanup:
if (privnet)
@@ -3494,9 +3484,9 @@ static int testConnectListInterfaces(virConnectPtr conn, char
**const names, int
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]);
if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) {
+ if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto no_memory;
+ goto error;
}
}
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
@@ -3505,8 +3495,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char
**const names, int
return n;
-no_memory:
- virReportOOMError();
+error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
@@ -3540,9 +3529,9 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char
**const nam
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]);
if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) {
+ if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto no_memory;
+ goto error;
}
}
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
@@ -3551,7 +3540,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char
**const nam
return n;
-no_memory:
+error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
@@ -3880,13 +3869,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool)
{
pool->def->allocation = defaultPoolAlloc;
pool->def->available = defaultPoolCap - defaultPoolAlloc;
- pool->configFile = strdup("\0");
- if (!pool->configFile) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
+ return VIR_STRDUP(pool->configFile, "\0");
}
static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
@@ -3989,9 +3972,9 @@ testConnectListStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]);
if (virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
- !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+ VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0)
{
virStoragePoolObjUnlock(privconn->pools.objs[i]);
- goto no_memory;
+ goto error;
}
virStoragePoolObjUnlock(privconn->pools.objs[i]);
}
@@ -3999,8 +3982,7 @@ testConnectListStoragePools(virConnectPtr conn,
return n;
-no_memory:
- virReportOOMError();
+error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
@@ -4036,9 +4018,9 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]);
if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
- !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+ VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0)
{
virStoragePoolObjUnlock(privconn->pools.objs[i]);
- goto no_memory;
+ goto error;
}
virStoragePoolObjUnlock(privconn->pools.objs[i]);
}
@@ -4046,8 +4028,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
return n;
-no_memory:
- virReportOOMError();
+error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
@@ -4178,9 +4159,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn
ATTRIBUTE_UNUSED,
switch (pool_type) {
case VIR_STORAGE_POOL_LOGICAL:
- ret = strdup(defaultPoolSourcesLogicalXML);
- if (!ret)
- virReportOOMError();
+ ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
break;
case VIR_STORAGE_POOL_NETFS:
@@ -4648,10 +4627,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
}
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
- if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0)
goto cleanup;
- }
}
virStoragePoolObjUnlock(privpool);
@@ -4910,11 +4887,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup;
}
- privvol->key = strdup(privvol->target.path);
- if (privvol->key == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
- }
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
@@ -5005,11 +4979,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup;
}
- privvol->key = strdup(privvol->target.path);
- if (privvol->key == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
- }
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
@@ -5233,9 +5204,7 @@ testStorageVolGetPath(virStorageVolPtr vol) {
goto cleanup;
}
- ret = strdup(privvol->target.path);
- if (ret == NULL)
- virReportOOMError();
+ ignore_value(VIR_STRDUP_QUIET(ret, privvol->target.path));
cleanup:
if (privpool)
@@ -5302,7 +5271,7 @@ testNodeListDevices(virConnectPtr conn,
virNodeDeviceObjLock(driver->devs.objs[i]);
if (cap == NULL ||
virNodeDeviceHasCap(driver->devs.objs[i], cap)) {
- if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) ==
NULL) {
+ if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) <
0) {
virNodeDeviceObjUnlock(driver->devs.objs[i]);
goto failure;
}
@@ -5393,9 +5362,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
}
if (obj->def->parent) {
- ret = strdup(obj->def->parent);
- if (!ret)
- virReportOOMError();
+ ignore_value(VIR_STRDUP_QUIET(ret, obj->def->parent));
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device"));
@@ -5460,9 +5427,9 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int
maxnames)
}
for (caps = obj->def->caps; caps && ncaps < maxnames; caps =
caps->next) {
- names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
- if (names[ncaps++] == NULL)
+ if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0)
goto cleanup;
+ ncaps++;
}
ret = ncaps;
@@ -5514,10 +5481,8 @@ testNodeDeviceCreateXML(virConnectPtr conn,
/* 'name' is supposed to be filled in by the node device backend, which
* we don't have. Use WWPN instead. */
VIR_FREE(def->name);
- if (!(def->name = strdup(wwpn))) {
- virReportOOMError();
+ if (VIR_STRDUP(def->name, wwpn) < 0)
goto cleanup;
- }
/* Fill in a random 'host' value, since this would also come from
* the backend */
@@ -5568,11 +5533,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
goto out;
}
- parent_name = strdup(obj->def->parent);
- if (parent_name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(parent_name, obj->def->parent) < 0)
goto out;
- }
/* virNodeDeviceGetParentHost will cause the device object's lock to be
* taken, so we have to dup the parent's name and drop the lock
@@ -5778,10 +5740,8 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL);
- if (!(ret = strdup("image/png"))) {
- virReportOOMError();
+ if (VIR_STRDUP(ret, "image/png") < 0)
return NULL;
- }
if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY
< 0))
VIR_FREE(ret);
--
1.8.1.5