diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 2bc217debbd71487053b1c52cd2a70300e273f80..74a52f0d7adb7f65d92313385a756900d4557a55 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -186,8 +186,8 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.file.path = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0) + return -1; } else if (virJSONValueObjectHasKey(value, "socket")) { chr->source.type = VIR_DOMAIN_CHR_TYPE_UNIX; @@ -197,8 +197,8 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.nix.path = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(chr->source.data.nix.path, tmp) < 0) + return -1; chr->source.data.nix.listen = false; } else if (virJSONValueObjectHasKey(value, "real")) { chr->source.type = VIR_DOMAIN_CHR_TYPE_DEV; @@ -209,18 +209,14 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.file.path = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0) + return -1; } else { parallelsParseError(); return -1; } return 0; - - no_memory: - virReportOOMError(); - return -1; } static int @@ -318,10 +314,8 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = strdup(tmp))) { - virReportOOMError(); + if (VIR_STRDUP(disk->src, tmp) < 0) return -1; - } } else { disk->type = VIR_DOMAIN_DISK_TYPE_FILE; @@ -330,10 +324,8 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = strdup(tmp))) { - virReportOOMError(); + if (VIR_STRDUP(disk->src, tmp) < 0) return -1; - } } tmp = virJSONValueObjectGetString(value, "port"); @@ -454,10 +446,8 @@ parallelsGetNetInfo(virDomainNetDefPtr net, /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ - if (!(net->ifname = strdup(key))) { - virReportOOMError(); + if (VIR_STRDUP(net->ifname, key) < 0) goto error; - } net->type = VIR_DOMAIN_NET_TYPE_NETWORK; @@ -478,10 +468,8 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = strdup(tmp))) { - virReportOOMError(); + if (VIR_STRDUP(net->data.network.name, tmp) < 0) goto error; - } } else if (virJSONValueObjectHasKey(value, "type")) { if (!(tmp = virJSONValueObjectGetString(value, "type"))) { parallelsParseError(); @@ -493,10 +481,9 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) { - virReportOOMError(); + if (VIR_STRDUP(net->data.network.name, + PARALLELS_ROUTED_NETWORK_NAME) < 0) goto error; - } } else { parallelsParseError(); goto error; @@ -641,8 +628,8 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) gr->nListens = 1; - if (!(gr->listens[0].address = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(gr->listens[0].address, tmp) < 0) + goto cleanup; gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; @@ -686,8 +673,8 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(def->name = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(def->name, tmp) < 0) + goto cleanup; if (!(tmp = virJSONValueObjectGetString(jobj, "ID"))) { parallelsParseError(); @@ -704,8 +691,8 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(def->description = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(def->description, tmp) < 0) + goto cleanup; if (!(jobj2 = virJSONValueObjectGet(jobj, "Hardware"))) { parallelsParseError(); @@ -771,13 +758,13 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) } if (STREQ(tmp, "CT")) { - if (!(def->os.type = strdup("exe"))) - goto no_memory; - if (!(def->os.init = strdup("/sbin/init"))) - goto no_memory; + if (VIR_STRDUP(def->os.type, "exe") < 0) + goto cleanup; + if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) + goto cleanup; } else if (STREQ(tmp, "VM")) { - if (!(def->os.type = strdup("hvm"))) - goto no_memory; + if (VIR_STRDUP(def->os.type, "hvm") < 0) + goto cleanup; } def->os.arch = VIR_ARCH_X86_64; @@ -792,16 +779,16 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(pdom->uuid = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(pdom->uuid, tmp) < 0) + goto cleanup; if (!(tmp = virJSONValueObjectGetString(jobj, "Home"))) { parallelsParseError(); goto cleanup; } - if (!(pdom->home = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(pdom->home, tmp) < 0) + goto cleanup; if (!(state = virJSONValueObjectGetString(jobj, "State"))) { parallelsParseError(); @@ -1246,8 +1233,7 @@ parallelsDomainGetOSType(virDomainPtr domain) goto cleanup; } - if (!(ret = strdup(privdom->def->os.type))) - virReportOOMError(); + ignore_value(VIR_STRDUP(ret, privdom->def->os.type)); cleanup: if (privdom) diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index 23109d38436c8c3f8d77a023f98848a323a02b21..2e5523b0310c1717828fbd842df29cc96e6e0c76 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -66,10 +66,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj goto cleanup; } - if (!(def->bridge = strdup(last_component(bridgePath)))) { - virReportOOMError(); + if (VIR_STRDUP(def->bridge, last_component(bridgePath)) < 0) goto cleanup; - } if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address", SYSFS_NET_DIR, ifname) < 0) { @@ -130,10 +128,9 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) goto cleanup; } - if (!(def->ips[0].family = strdup("ipv4"))) { - virReportOOMError(); + if (VIR_STRDUP(def->ips[0].family, "ipv4") < 0) goto cleanup; - }; + if (!(tmp = virJSONValueObjectGetString(jobj2, "IP address"))) { parallelsParseError(); goto cleanup; @@ -207,8 +204,8 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } - if (!(def->name = strdup(tmp))) - goto no_memory; + if (VIR_STRDUP(def->name, tmp) < 0) + goto cleanup; /* Network names are unique in Parallels Cloud Server, so we can make * an UUID from it */ @@ -264,8 +261,8 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) def->forward.type = VIR_NETWORK_FORWARD_ROUTE; - if (!(def->name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) - goto no_memory; + if (VIR_STRDUP(def->name, PARALLELS_ROUTED_NETWORK_NAME) < 0) + goto cleanup; if (virUUIDParse(PARALLELS_ROUTED_NETWORK_UUID, def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -390,9 +387,8 @@ static int parallelsConnectListNetworks(virConnectPtr conn, for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (virNetworkObjIsActive(privconn->networks.objs[i])) { - if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -438,9 +434,8 @@ static int parallelsConnectListDefinedNetworks(virConnectPtr conn, for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (!virNetworkObjIsActive(privconn->networks.objs[i])) { - if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 4c98e4389db6c666154c2b794f2328f6131c71dd..6a02fd6523981bafaa20f38deb244ad6bc76ddf4 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -136,20 +136,9 @@ static char *parallelsMakePoolName(virConnectPtr conn, const char *path) bool found = false; int j; - if (!(name = strdup(path))) { - virReportOOMError(); + if ((!i && VIR_STRDUP(name, path) < 0) || + (i && virAsprintf(&name, "%s-%u", path, i) < 0)) return NULL; - } - - if (i == 0) - name = strdup(path); - else - ignore_value(virAsprintf(&name, "%s-%u", path, i)); - - if (!name) { - virReportOOMError(); - return 0; - } for (j = 0; j < strlen(name); j++) if (name[j] == '/') @@ -195,7 +184,8 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path) } def->type = VIR_STORAGE_POOL_DIR; - def->target.path = strdup(path); + if (VIR_STRDUP(def->target.path, path) < 0) + goto error; if (!(pool = virStoragePoolObjAssignDef(pools, def))) goto error; @@ -324,8 +314,8 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, if (!(def->target.path = realpath(diskPath, NULL))) goto no_memory; - if (!(def->key = strdup(def->target.path))) - goto no_memory; + if (VIR_STRDUP(def->key, def->target.path) < 0) + goto error; if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) goto no_memory; @@ -425,8 +415,8 @@ static int parallelsLoadPools(virConnectPtr conn) char *base = NULL; size_t i; - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) + goto error; /* Configuration path is /etc/libvirt/parallels-storage/... . */ if (virAsprintf(&storageState->configDir, @@ -540,9 +530,9 @@ parallelsConnectListStoragePools(virConnectPtr conn, char **const names, int nna 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]); } @@ -550,8 +540,7 @@ parallelsConnectListStoragePools(virConnectPtr conn, char **const names, int nna return n; -no_memory: - virReportOOMError(); +error: for (n = 0; n < nnames; n++) VIR_FREE(names[n]); parallelsDriverUnlock(privconn); @@ -590,9 +579,9 @@ parallelsConnectListDefinedStoragePools(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]); } @@ -600,8 +589,7 @@ parallelsConnectListDefinedStoragePools(virConnectPtr conn, return n; -no_memory: - virReportOOMError(); +error: for (n = 0; n < nnames; n++) VIR_FREE(names[n]); parallelsDriverUnlock(privconn); @@ -758,11 +746,8 @@ parallelsStoragePoolDefineXML(virConnectPtr conn, } def = NULL; - pool->configFile = strdup("\0"); - if (!pool->configFile) { - virReportOOMError(); + if (VIR_STRDUP(pool->configFile, "\0") < 0) goto cleanup; - } ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, NULL, NULL); @@ -1085,10 +1070,8 @@ parallelsStoragePoolListVolumes(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 error; - } } virStoragePoolObjUnlock(privpool); @@ -1271,11 +1254,8 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr 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; - } if (is_new) { xml_path = parallelsAddFileExt(privvol->target.path, ".xml"); @@ -1412,11 +1392,8 @@ parallelsStorageVolCreateXMLFrom(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 - @@ -1659,9 +1636,7 @@ parallelsStorageVolGetPath(virStorageVolPtr vol) goto cleanup; } - ret = strdup(privvol->target.path); - if (ret == NULL) - virReportOOMError(); + ignore_value(VIR_STRDUP(ret, privvol->target.path)); cleanup: if (privpool)