提交 c03ae952 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/test/*

上级 3cef9f6a
...@@ -219,18 +219,17 @@ testBuildCapabilities(virConnectPtr conn) { ...@@ -219,18 +219,17 @@ 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 no_memory; goto no_memory;
caps->host.secModels[0].model = strdup("testSecurity"); if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0)
if (!caps->host.secModels[0].model) goto error;
goto no_memory;
caps->host.secModels[0].doi = strdup(""); if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0)
if (!caps->host.secModels[0].doi) goto error;
goto no_memory;
return caps; return caps;
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
virObjectUnref(caps); virObjectUnref(caps);
return NULL; return NULL;
} }
...@@ -673,10 +672,14 @@ static char *testBuildFilename(const char *relativeTo, ...@@ -673,10 +672,14 @@ static char *testBuildFilename(const char *relativeTo,
const char *filename) { const char *filename) {
char *offset; char *offset;
int baseLen; int baseLen;
char *ret;
if (!filename || filename[0] == '\0') if (!filename || filename[0] == '\0')
return NULL; return NULL;
if (filename[0] == '/') if (filename[0] == '/') {
return strdup(filename); ignore_value(VIR_STRDUP(ret, filename));
return ret;
}
offset = strrchr(relativeTo, '/'); offset = strrchr(relativeTo, '/');
if ((baseLen = (offset-relativeTo+1))) { if ((baseLen = (offset-relativeTo+1))) {
...@@ -691,7 +694,8 @@ static char *testBuildFilename(const char *relativeTo, ...@@ -691,7 +694,8 @@ static char *testBuildFilename(const char *relativeTo,
strcat(absFile, filename); strcat(absFile, filename);
return absFile; return absFile;
} else { } else {
return strdup(filename); ignore_value(VIR_STRDUP(ret, filename));
return ret;
} }
} }
...@@ -754,13 +758,8 @@ static int testOpenVolumesForPool(xmlDocPtr xml, ...@@ -754,13 +758,8 @@ static int testOpenVolumesForPool(xmlDocPtr xml,
} }
} }
if (def->key == NULL) { if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0)
def->key = strdup(def->target.path); goto error;
if (def->key == NULL) {
virReportOOMError();
goto error;
}
}
pool->def->allocation += def->allocation; pool->def->allocation += def->allocation;
pool->def->available = (pool->def->capacity - pool->def->available = (pool->def->capacity -
...@@ -826,10 +825,8 @@ static int testOpenFromFile(virConnectPtr conn, ...@@ -826,10 +825,8 @@ static int testOpenFromFile(virConnectPtr conn,
privconn->nextDomID = 1; privconn->nextDomID = 1;
privconn->numCells = 0; privconn->numCells = 0;
if ((privconn->path = strdup(file)) == NULL) { if (VIR_STRDUP(privconn->path, file) < 0)
virReportOOMError();
goto error; goto error;
}
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo)); memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo; nodeInfo = &privconn->nodeInfo;
...@@ -2066,9 +2063,9 @@ cleanup: ...@@ -2066,9 +2063,9 @@ cleanup:
} }
static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
char *ret = strdup("linux"); char *ret;
if (!ret)
virReportOOMError(); ignore_value(VIR_STRDUP(ret, "linux"));
return ret; return ret;
} }
...@@ -2726,9 +2723,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, ...@@ -2726,9 +2723,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
if (nparams) if (nparams)
*nparams = 1; *nparams = 1;
type = strdup("fair"); ignore_value(VIR_STRDUP(type, "fair"));
if (!type)
virReportOOMError();
return type; return type;
} }
...@@ -3026,9 +3021,9 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n ...@@ -3026,9 +3021,9 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]); virNetworkObjLock(privconn->networks.objs[i]);
if (virNetworkObjIsActive(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]); virNetworkObjUnlock(privconn->networks.objs[i]);
goto no_memory; goto error;
} }
virNetworkObjUnlock(privconn->networks.objs[i]); virNetworkObjUnlock(privconn->networks.objs[i]);
} }
...@@ -3036,8 +3031,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n ...@@ -3036,8 +3031,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -3069,9 +3063,9 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names ...@@ -3069,9 +3063,9 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]); virNetworkObjLock(privconn->networks.objs[i]);
if (!virNetworkObjIsActive(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]); virNetworkObjUnlock(privconn->networks.objs[i]);
goto no_memory; goto error;
} }
virNetworkObjUnlock(privconn->networks.objs[i]); virNetworkObjUnlock(privconn->networks.objs[i]);
} }
...@@ -3079,8 +3073,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names ...@@ -3079,8 +3073,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -3387,10 +3380,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { ...@@ -3387,10 +3380,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
goto cleanup; goto cleanup;
} }
if (!(bridge = strdup(privnet->def->bridge))) { ignore_value(VIR_STRDUP(bridge, privnet->def->bridge));
virReportOOMError();
goto cleanup;
}
cleanup: cleanup:
if (privnet) if (privnet)
...@@ -3500,9 +3490,9 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int ...@@ -3500,9 +3490,9 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]); virInterfaceObjLock(privconn->ifaces.objs[i]);
if (virInterfaceObjIsActive(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]); virInterfaceObjUnlock(privconn->ifaces.objs[i]);
goto no_memory; goto error;
} }
} }
virInterfaceObjUnlock(privconn->ifaces.objs[i]); virInterfaceObjUnlock(privconn->ifaces.objs[i]);
...@@ -3511,8 +3501,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int ...@@ -3511,8 +3501,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -3546,9 +3535,9 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam ...@@ -3546,9 +3535,9 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]); virInterfaceObjLock(privconn->ifaces.objs[i]);
if (!virInterfaceObjIsActive(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]); virInterfaceObjUnlock(privconn->ifaces.objs[i]);
goto no_memory; goto error;
} }
} }
virInterfaceObjUnlock(privconn->ifaces.objs[i]); virInterfaceObjUnlock(privconn->ifaces.objs[i]);
...@@ -3557,8 +3546,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam ...@@ -3557,8 +3546,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -3886,13 +3874,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { ...@@ -3886,13 +3874,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
pool->def->allocation = defaultPoolAlloc; pool->def->allocation = defaultPoolAlloc;
pool->def->available = defaultPoolCap - defaultPoolAlloc; pool->def->available = defaultPoolCap - defaultPoolAlloc;
pool->configFile = strdup("\0"); return VIR_STRDUP(pool->configFile, "");
if (!pool->configFile) {
virReportOOMError();
return -1;
}
return 0;
} }
static virDrvOpenStatus testStorageOpen(virConnectPtr conn, static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
...@@ -3995,9 +3977,9 @@ testConnectListStoragePools(virConnectPtr conn, ...@@ -3995,9 +3977,9 @@ testConnectListStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) { for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]); virStoragePoolObjLock(privconn->pools.objs[i]);
if (virStoragePoolObjIsActive(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]); virStoragePoolObjUnlock(privconn->pools.objs[i]);
goto no_memory; goto error;
} }
virStoragePoolObjUnlock(privconn->pools.objs[i]); virStoragePoolObjUnlock(privconn->pools.objs[i]);
} }
...@@ -4005,8 +3987,7 @@ testConnectListStoragePools(virConnectPtr conn, ...@@ -4005,8 +3987,7 @@ testConnectListStoragePools(virConnectPtr conn,
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -4042,9 +4023,9 @@ testConnectListDefinedStoragePools(virConnectPtr conn, ...@@ -4042,9 +4023,9 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) { for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]); virStoragePoolObjLock(privconn->pools.objs[i]);
if (!virStoragePoolObjIsActive(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]); virStoragePoolObjUnlock(privconn->pools.objs[i]);
goto no_memory; goto error;
} }
virStoragePoolObjUnlock(privconn->pools.objs[i]); virStoragePoolObjUnlock(privconn->pools.objs[i]);
} }
...@@ -4052,8 +4033,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn, ...@@ -4052,8 +4033,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
return n; return n;
no_memory: error:
virReportOOMError();
for (n = 0 ; n < nnames ; n++) for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]); VIR_FREE(names[n]);
testDriverUnlock(privconn); testDriverUnlock(privconn);
...@@ -4184,9 +4164,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -4184,9 +4164,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
switch (pool_type) { switch (pool_type) {
case VIR_STORAGE_POOL_LOGICAL: case VIR_STORAGE_POOL_LOGICAL:
ret = strdup(defaultPoolSourcesLogicalXML); ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
if (!ret)
virReportOOMError();
break; break;
case VIR_STORAGE_POOL_NETFS: case VIR_STORAGE_POOL_NETFS:
...@@ -4654,10 +4632,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, ...@@ -4654,10 +4632,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
} }
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) { 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; goto cleanup;
}
} }
virStoragePoolObjUnlock(privpool); virStoragePoolObjUnlock(privpool);
...@@ -4916,11 +4892,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool, ...@@ -4916,11 +4892,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
privvol->key = strdup(privvol->target.path); if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
if (privvol->key == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
privpool->def->allocation += privvol->allocation; privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
...@@ -5011,11 +4984,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, ...@@ -5011,11 +4984,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
privvol->key = strdup(privvol->target.path); if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
if (privvol->key == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
privpool->def->allocation += privvol->allocation; privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity - privpool->def->available = (privpool->def->capacity -
...@@ -5239,9 +5209,7 @@ testStorageVolGetPath(virStorageVolPtr vol) { ...@@ -5239,9 +5209,7 @@ testStorageVolGetPath(virStorageVolPtr vol) {
goto cleanup; goto cleanup;
} }
ret = strdup(privvol->target.path); ignore_value(VIR_STRDUP(ret, privvol->target.path));
if (ret == NULL)
virReportOOMError();
cleanup: cleanup:
if (privpool) if (privpool)
...@@ -5308,7 +5276,7 @@ testNodeListDevices(virConnectPtr conn, ...@@ -5308,7 +5276,7 @@ testNodeListDevices(virConnectPtr conn,
virNodeDeviceObjLock(driver->devs.objs[i]); virNodeDeviceObjLock(driver->devs.objs[i]);
if (cap == NULL || if (cap == NULL ||
virNodeDeviceHasCap(driver->devs.objs[i], cap)) { 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]); virNodeDeviceObjUnlock(driver->devs.objs[i]);
goto failure; goto failure;
} }
...@@ -5399,9 +5367,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) ...@@ -5399,9 +5367,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
} }
if (obj->def->parent) { if (obj->def->parent) {
ret = strdup(obj->def->parent); ignore_value(VIR_STRDUP(ret, obj->def->parent));
if (!ret)
virReportOOMError();
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device")); "%s", _("no parent for this device"));
...@@ -5466,8 +5432,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) ...@@ -5466,8 +5432,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
} }
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->type)) < 0)
if (names[ncaps++] == NULL)
goto cleanup; goto cleanup;
} }
ret = ncaps; ret = ncaps;
...@@ -5520,10 +5485,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5520,10 +5485,8 @@ testNodeDeviceCreateXML(virConnectPtr conn,
/* 'name' is supposed to be filled in by the node device backend, which /* 'name' is supposed to be filled in by the node device backend, which
* we don't have. Use WWPN instead. */ * we don't have. Use WWPN instead. */
VIR_FREE(def->name); VIR_FREE(def->name);
if (!(def->name = strdup(wwpn))) { if (VIR_STRDUP(def->name, wwpn) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* Fill in a random 'host' value, since this would also come from /* Fill in a random 'host' value, since this would also come from
* the backend */ * the backend */
...@@ -5574,11 +5537,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -5574,11 +5537,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
goto out; goto out;
} }
parent_name = strdup(obj->def->parent); if (VIR_STRDUP(parent_name, obj->def->parent) < 0)
if (parent_name == NULL) {
virReportOOMError();
goto out; goto out;
}
/* virNodeDeviceGetParentHost will cause the device object's lock to be /* virNodeDeviceGetParentHost will cause the device object's lock to be
* taken, so we have to dup the parent's name and drop the lock * taken, so we have to dup the parent's name and drop the lock
...@@ -5784,10 +5744,8 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, ...@@ -5784,10 +5744,8 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (!(ret = strdup("image/png"))) { if (VIR_STRDUP(ret, "image/png") < 0)
virReportOOMError();
return NULL; return NULL;
}
if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0)) if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0))
VIR_FREE(ret); VIR_FREE(ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册