--- src/test/test_driver.c | 82 +++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f60f106..b7c121e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -219,12 +219,10 @@ 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) + if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0) goto no_memory; - caps->host.secModels[0].doi = strdup(""); - if (!caps->host.secModels[0].doi) + if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0) goto no_memory; return caps; @@ -673,10 +671,14 @@ static char *testBuildFilename(const char *relativeTo, const char *filename) { char *offset; int baseLen; + char *ret = NULL; + 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 +693,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,12 +757,9 @@ 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) { + virReportOOMError(); + goto error; } pool->def->allocation += def->allocation; @@ -826,7 +826,7 @@ static int testOpenFromFile(virConnectPtr conn, privconn->nextDomID = 1; privconn->numCells = 0; - if ((privconn->path = strdup(file)) == NULL) { + if (VIR_STRDUP(privconn->path, file) < 0) { virReportOOMError(); goto error; } @@ -2060,8 +2060,9 @@ cleanup: } static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { - char *ret = strdup("linux"); - if (!ret) + char *ret; + + if (VIR_STRDUP(ret, "linux") < 0) virReportOOMError(); return ret; } @@ -2720,8 +2721,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, if (nparams) *nparams = 1; - type = strdup("fair"); - if (!type) + if (VIR_STRDUP(type, "fair") < 0) virReportOOMError(); return type; @@ -3020,7 +3020,7 @@ 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; } @@ -3063,7 +3063,7 @@ 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; } @@ -3381,7 +3381,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { goto cleanup; } - if (!(bridge = strdup(privnet->def->bridge))) { + if (VIR_STRDUP(bridge, privnet->def->bridge) < 0) { virReportOOMError(); goto cleanup; } @@ -3494,7 +3494,7 @@ 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; } @@ -3540,7 +3540,7 @@ 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; } @@ -3880,8 +3880,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { pool->def->allocation = defaultPoolAlloc; pool->def->available = defaultPoolCap - defaultPoolAlloc; - pool->configFile = strdup("\0"); - if (!pool->configFile) { + if (VIR_STRDUP(pool->configFile, "\0") < 0) { virReportOOMError(); return -1; } @@ -3989,7 +3988,7 @@ 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; } @@ -4036,7 +4035,7 @@ 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; } @@ -4178,8 +4177,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, switch (pool_type) { case VIR_STORAGE_POOL_LOGICAL: - ret = strdup(defaultPoolSourcesLogicalXML); - if (!ret) + if (VIR_STRDUP(ret, defaultPoolSourcesLogicalXML) < 0) virReportOOMError(); break; @@ -4648,7 +4646,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, } for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) { + if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0) { virReportOOMError(); goto cleanup; } @@ -4910,8 +4908,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -5005,8 +5002,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -5233,8 +5229,7 @@ testStorageVolGetPath(virStorageVolPtr vol) { goto cleanup; } - ret = strdup(privvol->target.path); - if (ret == NULL) + if (VIR_STRDUP(ret, privvol->target.path) < 0) virReportOOMError(); cleanup: @@ -5302,7 +5297,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,8 +5388,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) } if (obj->def->parent) { - ret = strdup(obj->def->parent); - if (!ret) + if (VIR_STRDUP(ret, obj->def->parent) < 0) virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -5460,8 +5454,7 @@ 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; } ret = ncaps; @@ -5514,7 +5507,7 @@ 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))) { + if (VIR_STRDUP(def->name, wwpn) < 0) { virReportOOMError(); goto cleanup; } @@ -5568,8 +5561,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) goto out; } - parent_name = strdup(obj->def->parent); - if (parent_name == NULL) { + if (VIR_STRDUP(parent_name, obj->def->parent) < 0) { virReportOOMError(); goto out; } @@ -5778,7 +5770,7 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, virCheckFlags(0, NULL); - if (!(ret = strdup("image/png"))) { + if (VIR_STRDUP(ret, "image/png") < 0) { virReportOOMError(); return NULL; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list