Adapt to VIR_STRDUP and VIR_STRNDUP in src/qemu/*

This commit is contained in:
Michal Privoznik 2013-05-20 11:23:13 +02:00
parent c0955c3206
commit a88fb3009f
11 changed files with 349 additions and 601 deletions

View File

@ -371,8 +371,8 @@ virQEMUCapsParseMachineTypesStr(const char *output,
if (!(t = strchr(p, ' ')) || (next && t >= next)) if (!(t = strchr(p, ' ')) || (next && t >= next))
continue; continue;
if (!(name = strndup(p, t - p))) if (VIR_STRNDUP(name, p, t - p) < 0)
goto no_memory; return -1;
p = t; p = t;
if ((t = strstr(p, "(default)")) && (!next || t < next)) if ((t = strstr(p, "(default)")) && (!next || t < next))
@ -383,9 +383,9 @@ virQEMUCapsParseMachineTypesStr(const char *output,
if (!(t = strchr(p, ')')) || (next && t >= next)) if (!(t = strchr(p, ')')) || (next && t >= next))
continue; continue;
if (!(canonical = strndup(p, t - p))) { if (VIR_STRNDUP(canonical, p, t - p) < 0) {
VIR_FREE(name); VIR_FREE(name);
goto no_memory; return -1;
} }
} }
@ -393,7 +393,8 @@ virQEMUCapsParseMachineTypesStr(const char *output,
VIR_REALLOC_N(qemuCaps->machineAliases, qemuCaps->nmachineTypes + 1) < 0) { VIR_REALLOC_N(qemuCaps->machineAliases, qemuCaps->nmachineTypes + 1) < 0) {
VIR_FREE(name); VIR_FREE(name);
VIR_FREE(canonical); VIR_FREE(canonical);
goto no_memory; virReportOOMError();
return -1;
} }
qemuCaps->nmachineTypes++; qemuCaps->nmachineTypes++;
if (canonical) { if (canonical) {
@ -410,10 +411,6 @@ virQEMUCapsParseMachineTypesStr(const char *output,
virQEMUCapsSetDefaultMachine(qemuCaps, defIdx); virQEMUCapsSetDefaultMachine(qemuCaps, defIdx);
return 0; return 0;
no_memory:
virReportOOMError();
return -1;
} }
static int static int
@ -508,10 +505,8 @@ virQEMUCapsParseX86Models(const char *output,
len -= 2; len -= 2;
} }
if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) { if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} while ((p = next)); } while ((p = next));
ret = 0; ret = 0;
@ -561,10 +556,8 @@ virQEMUCapsParsePPCModels(const char *output,
len = t - p - 1; len = t - p - 1;
if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) { if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} while ((p = next)); } while ((p = next));
ret = 0; ret = 0;
@ -1516,10 +1509,8 @@ virQEMUCapsParseDeviceStrObjectTypes(const char *str,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (!(typelist[ntypelist-1] = strndup(tmp, end-tmp))) { if (VIR_STRNDUP(typelist[ntypelist - 1], tmp, end-tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
*types = typelist; *types = typelist;
@ -1573,10 +1564,8 @@ virQEMUCapsParseDeviceStrObjectProps(const char *str,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (!(proplist[nproplist-1] = strndup(tmp, end-tmp))) { if (VIR_STRNDUP(proplist[nproplist - 1], tmp, end-tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
*props = proplist; *props = proplist;
@ -1745,8 +1734,8 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
goto no_memory; goto no_memory;
ret->ncpuDefinitions = qemuCaps->ncpuDefinitions; ret->ncpuDefinitions = qemuCaps->ncpuDefinitions;
for (i = 0; i < qemuCaps->ncpuDefinitions; i++) { for (i = 0; i < qemuCaps->ncpuDefinitions; i++) {
if (!(ret->cpuDefinitions[i] = strdup(qemuCaps->cpuDefinitions[i]))) if (VIR_STRDUP(ret->cpuDefinitions[i], qemuCaps->cpuDefinitions[i]) < 0)
goto no_memory; goto error;
} }
if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0) if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
@ -1755,17 +1744,16 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
goto no_memory; goto no_memory;
ret->nmachineTypes = qemuCaps->nmachineTypes; ret->nmachineTypes = qemuCaps->nmachineTypes;
for (i = 0; i < qemuCaps->nmachineTypes; i++) { for (i = 0; i < qemuCaps->nmachineTypes; i++) {
if (!(ret->machineTypes[i] = strdup(qemuCaps->machineTypes[i]))) if (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0 ||
goto no_memory; VIR_STRDUP(ret->machineAliases[i], qemuCaps->machineAliases[i]) < 0)
if (qemuCaps->machineAliases[i] && goto error;
!(ret->machineAliases[i] = strdup(qemuCaps->machineAliases[i])))
goto no_memory;
} }
return ret; return ret;
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
virObjectUnref(ret); virObjectUnref(ret);
return NULL; return NULL;
} }
@ -1867,11 +1855,10 @@ unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps)
int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps, int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps,
const char *name) const char *name)
{ {
char *tmp = strdup(name); char *tmp;
if (!tmp) {
virReportOOMError(); if (VIR_STRDUP(tmp, name) < 0)
return -1; return -1;
}
if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) { if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) {
VIR_FREE(tmp); VIR_FREE(tmp);
virReportOOMError(); virReportOOMError();
@ -1908,28 +1895,27 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
*nmachines = 0; *nmachines = 0;
*machines = NULL; *machines = NULL;
if (VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0) if (VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0)
goto no_memory; goto error;
*nmachines = qemuCaps->nmachineTypes; *nmachines = qemuCaps->nmachineTypes;
for (i = 0; i < qemuCaps->nmachineTypes; i++) { for (i = 0; i < qemuCaps->nmachineTypes; i++) {
virCapsGuestMachinePtr mach; virCapsGuestMachinePtr mach;
if (VIR_ALLOC(mach) < 0) if (VIR_ALLOC(mach) < 0)
goto no_memory; goto error;
if (qemuCaps->machineAliases[i]) { if (qemuCaps->machineAliases[i]) {
if (!(mach->name = strdup(qemuCaps->machineAliases[i]))) if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0 ||
goto no_memory; VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
if (!(mach->canonical = strdup(qemuCaps->machineTypes[i]))) goto error;
goto no_memory;
} else { } else {
if (!(mach->name = strdup(qemuCaps->machineTypes[i]))) if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i]) < 0)
goto no_memory; goto error;
} }
(*machines)[i] = mach; (*machines)[i] = mach;
} }
return 0; return 0;
no_memory: error:
virCapabilitiesFreeMachines(*machines, *nmachines); virCapabilitiesFreeMachines(*machines, *nmachines);
*nmachines = 0; *nmachines = 0;
*machines = NULL; *machines = NULL;
@ -2110,16 +2096,9 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
} }
for (i = 0; i < nmachines; i++) { for (i = 0; i < nmachines; i++) {
if (machines[i]->alias) { if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0 ||
if (!(qemuCaps->machineAliases[i] = strdup(machines[i]->alias))) { VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0)
virReportOOMError();
goto cleanup;
}
}
if (!(qemuCaps->machineTypes[i] = strdup(machines[i]->name))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
if (machines[i]->isDefault) if (machines[i]->isDefault)
defIdx = i; defIdx = i;
} }
@ -2671,8 +2650,8 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
struct stat sb; struct stat sb;
int rv; int rv;
if (!(qemuCaps->binary = strdup(binary))) if (VIR_STRDUP(qemuCaps->binary, binary) < 0)
goto no_memory; goto error;
/* We would also want to check faccessat if we cared about ACLs, /* We would also want to check faccessat if we cared about ACLs,
* but we don't. */ * but we don't. */
@ -2702,8 +2681,6 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
return qemuCaps; return qemuCaps;
no_memory:
virReportOOMError();
error: error:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
qemuCaps = NULL; qemuCaps = NULL;
@ -2753,10 +2730,8 @@ virQEMUCapsCacheNew(const char *libDir,
if (!(cache->binaries = virHashCreate(10, virQEMUCapsHashDataFree))) if (!(cache->binaries = virHashCreate(10, virQEMUCapsHashDataFree)))
goto error; goto error;
if (!(cache->libDir = strdup(libDir))) { if (VIR_STRDUP(cache->libDir, libDir) < 0)
virReportOOMError();
goto error; goto error;
}
cache->runUid = runUid; cache->runUid = runUid;
cache->runGid = runGid; cache->runGid = runGid;

View File

@ -32,6 +32,7 @@
#include "virerror.h" #include "virerror.h"
#include "domain_audit.h" #include "domain_audit.h"
#include "virscsi.h" #include "virscsi.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
@ -697,8 +698,7 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (!(res->partition = strdup("/machine"))) { if (VIR_STRDUP(res->partition, "/machine") < 0) {
virReportOOMError();
VIR_FREE(res); VIR_FREE(res);
goto cleanup; goto cleanup;
} }

View File

@ -326,10 +326,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
return ret; return ret;
} else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) { if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0)
virReportOOMError();
return ret; return ret;
}
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"), _("Network type %d is not supported"),
@ -341,10 +339,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) { strchr(net->ifname, '%')) {
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) { if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* avoid exposing vnet%d in getXMLDesc or error outputs */ /* avoid exposing vnet%d in getXMLDesc or error outputs */
template_ifname = true; template_ifname = true;
} }
@ -583,17 +579,10 @@ static int qemuAssignDeviceDiskAliasLegacy(virDomainDiskDefPtr disk)
{ {
char *dev_name; char *dev_name;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && if (VIR_STRDUP(dev_name,
STREQ(disk->dst, "hdc")) disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
dev_name = strdup("cdrom"); STREQ(disk->dst, "hdc") ? "cdrom" : disk->dst) < 0)
else
dev_name = strdup(disk->dst);
if (!dev_name) {
virReportOOMError();
return -1; return -1;
}
disk->info.alias = dev_name; disk->info.alias = dev_name;
return 0; return 0;
} }
@ -610,10 +599,7 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
return NULL; return NULL;
} }
} else { } else {
if (!(ret = strdup(disk->info.alias))) { ignore_value(VIR_STRDUP(ret, disk->info.alias));
virReportOOMError();
return NULL;
}
} }
return ret; return ret;
} }
@ -2531,13 +2517,11 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport)
if (port) { if (port) {
*port = '\0'; *port = '\0';
port += skip; port += skip;
disk->hosts[disk->nhosts-1].port = strdup(port); if (VIR_STRDUP(disk->hosts[disk->nhosts - 1].port, port) < 0)
if (!disk->hosts[disk->nhosts-1].port) goto error;
goto no_memory;
} else { } else {
disk->hosts[disk->nhosts-1].port = strdup("6789"); if (VIR_STRDUP(disk->hosts[disk->nhosts - 1].port, "6789") < 0)
if (!disk->hosts[disk->nhosts-1].port) goto error;
goto no_memory;
} }
parts = virStringSplit(hostport, "\\:", 0); parts = virStringSplit(hostport, "\\:", 0);
@ -2555,6 +2539,7 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport)
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
VIR_FREE(disk->hosts[disk->nhosts-1].port); VIR_FREE(disk->hosts[disk->nhosts-1].port);
VIR_FREE(disk->hosts[disk->nhosts-1].name); VIR_FREE(disk->hosts[disk->nhosts-1].name);
return -1; return -1;
@ -2568,9 +2553,8 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
p = strchr(disk->src, ':'); p = strchr(disk->src, ':');
if (p) { if (p) {
options = strdup(p + 1); if (VIR_STRDUP(options, p + 1) < 0)
if (!options) goto error;
goto no_memory;
*p = '\0'; *p = '\0';
} }
@ -2595,11 +2579,9 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
*e = '\0'; *e = '\0';
} }
if (STRPREFIX(p, "id=")) { if (STRPREFIX(p, "id=") &&
disk->auth.username = strdup(p + strlen("id=")); VIR_STRDUP(disk->auth.username, p + strlen("id=")) < 0)
if (!disk->auth.username) goto error;
goto no_memory;
}
if (STRPREFIX(p, "mon_host=")) { if (STRPREFIX(p, "mon_host=")) {
char *h, *sep; char *h, *sep;
@ -2626,9 +2608,8 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
VIR_FREE(options); VIR_FREE(options);
return 0; return 0;
no_memory: error:
VIR_FREE(options); VIR_FREE(options);
virReportOOMError();
return -1; return -1;
} }
@ -2668,9 +2649,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
def->nhosts = 0; /* set to 1 once everything succeeds */ def->nhosts = 0; /* set to 1 once everything succeeds */
if (def->hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) { if (def->hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) {
def->hosts->name = strdup(uri->server); if (VIR_STRDUP(def->hosts->name, uri->server) < 0)
if (!def->hosts->name) goto error;
goto no_memory;
if (virAsprintf(&def->hosts->port, "%d", uri->port) < 0) if (virAsprintf(&def->hosts->port, "%d", uri->port) < 0)
goto no_memory; goto no_memory;
@ -2680,9 +2660,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
if (uri->query) { if (uri->query) {
if (STRPREFIX(uri->query, "socket=")) { if (STRPREFIX(uri->query, "socket=")) {
sock = strchr(uri->query, '=') + 1; sock = strchr(uri->query, '=') + 1;
def->hosts->socket = strdup(sock); if (VIR_STRDUP(def->hosts->socket, sock) < 0)
if (!def->hosts->socket) goto error;
goto no_memory;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid query parameter '%s'"), uri->query); _("Invalid query parameter '%s'"), uri->query);
@ -2693,9 +2672,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
if (uri->path) { if (uri->path) {
volimg = uri->path + 1; /* skip the prefix slash */ volimg = uri->path + 1; /* skip the prefix slash */
VIR_FREE(def->src); VIR_FREE(def->src);
def->src = strdup(volimg); if (VIR_STRDUP(def->src, volimg) < 0)
if (!def->src) goto error;
goto no_memory;
} else { } else {
VIR_FREE(def->src); VIR_FREE(def->src);
def->src = NULL; def->src = NULL;
@ -2706,9 +2684,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
if (secret) if (secret)
*secret = '\0'; *secret = '\0';
def->auth.username = strdup(uri->user); if (VIR_STRDUP(def->auth.username, uri->user) < 0)
if (!def->auth.username) goto error;
goto no_memory;
} }
def->nhosts = 1; def->nhosts = 1;
@ -2788,7 +2765,8 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
*src++ = '\0'; *src++ = '\0';
h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX; h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX;
h->socket = strdup(host + strlen("unix:")); if (VIR_STRDUP(h->socket, host + strlen("unix:")) < 0)
goto error;
} else { } else {
port = strchr(host, ':'); port = strchr(host, ':');
if (!port) { if (!port) {
@ -2798,23 +2776,20 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
} }
*port++ = '\0'; *port++ = '\0';
h->name = strdup(host); if (VIR_STRDUP(h->name, host) < 0)
if (!h->name) goto error;
goto no_memory;
src = strchr(port, ':'); src = strchr(port, ':');
if (src) if (src)
*src++ = '\0'; *src++ = '\0';
h->port = strdup(port); if (VIR_STRDUP(h->port, port) < 0)
if (!h->port) goto error;
goto no_memory;
} }
if (src && STRPREFIX(src, "exportname=")) { if (src && STRPREFIX(src, "exportname=")) {
src = strdup(strchr(src, '=') + 1); if (VIR_STRDUP(src, strchr(src, '=') + 1) < 0)
if (!src) goto error;
goto no_memory;
} else { } else {
src = NULL; src = NULL;
} }
@ -2864,9 +2839,8 @@ qemuBuildDriveURIString(virConnectPtr conn,
transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport); transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport);
if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) { if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
tmpscheme = strdup(scheme); if (VIR_STRDUP(tmpscheme, scheme) < 0)
if (tmpscheme == NULL) goto cleanup;
goto no_memory;
} else { } else {
if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0) if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0)
goto no_memory; goto no_memory;
@ -5711,9 +5685,12 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
} }
virBufferAddLit(&buf, "host"); virBufferAddLit(&buf, "host");
} else { } else {
if (VIR_ALLOC(guest) < 0 || if (VIR_ALLOC(guest) < 0) {
(cpu->vendor_id && !(guest->vendor_id = strdup(cpu->vendor_id)))) virReportOOMError();
goto no_memory; goto cleanup;
}
if (VIR_STRDUP(guest->vendor_id, cpu->vendor_id) < 0)
goto cleanup;
guest->arch = host->arch; guest->arch = host->arch;
if (cpu->match == VIR_CPU_MATCH_MINIMUM) if (cpu->match == VIR_CPU_MATCH_MINIMUM)
@ -5812,8 +5789,10 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
} }
} }
if (virBufferError(&buf)) if (virBufferError(&buf)) {
goto no_memory; virReportOOMError();
goto cleanup;
}
*opt = virBufferContentAndReset(&buf); *opt = virBufferContentAndReset(&buf);
@ -5827,10 +5806,6 @@ cleanup:
virCPUDefFree(cpu); virCPUDefFree(cpu);
virObjectUnref(caps); virObjectUnref(caps);
return ret; return ret;
no_memory:
virReportOOMError();
goto cleanup;
} }
static int static int
@ -7525,14 +7500,15 @@ qemuBuildCommandLine(virConnectPtr conn,
fmt = "fat:%s"; fmt = "fat:%s";
if (virAsprintf(&file, fmt, disk->src) < 0) { if (virAsprintf(&file, fmt, disk->src) < 0) {
goto no_memory; virReportOOMError();
goto error;
} }
} else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { } else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network disks are only supported with -drive")); _("network disks are only supported with -drive"));
} else { } else {
if (!(file = strdup(disk->src))) { if (VIR_STRDUP(file, disk->src) < 0) {
goto no_memory; goto error;
} }
} }
@ -8176,8 +8152,10 @@ qemuBuildCommandLine(virConnectPtr conn,
} else { } else {
int size = 100; int size = 100;
char *modstr; char *modstr;
if (VIR_ALLOC_N(modstr, size+1) < 0) if (VIR_ALLOC_N(modstr, size+1) < 0) {
goto no_memory; virReportOOMError();
goto error;
}
for (i = 0; i < def->nsounds && size > 0; i++) { for (i = 0; i < def->nsounds && size > 0; i++) {
virDomainSoundDefPtr sound = def->sounds[i]; virDomainSoundDefPtr sound = def->sounds[i];
@ -8227,8 +8205,8 @@ qemuBuildCommandLine(virConnectPtr conn,
goto error; goto error;
} }
if (!(optstr = strdup(model))) if (VIR_STRDUP(optstr, model) < 0)
goto no_memory; goto error;
} }
virCommandAddArg(cmd, optstr); virCommandAddArg(cmd, optstr);
VIR_FREE(optstr); VIR_FREE(optstr);
@ -8374,7 +8352,8 @@ qemuBuildCommandLine(virConnectPtr conn,
if (configfd >= 0) { if (configfd >= 0) {
if (virAsprintf(&configfd_name, "%d", configfd) < 0) { if (virAsprintf(&configfd_name, "%d", configfd) < 0) {
VIR_FORCE_CLOSE(configfd); VIR_FORCE_CLOSE(configfd);
goto no_memory; virReportOOMError();
goto error;
} }
virCommandTransferFD(cmd, configfd); virCommandTransferFD(cmd, configfd);
@ -8583,8 +8562,6 @@ qemuBuildCommandLine(virConnectPtr conn,
virObjectUnref(cfg); virObjectUnref(cfg);
return cmd; return cmd;
no_memory:
virReportOOMError();
error: error:
virObjectUnref(cfg); virObjectUnref(cfg);
/* free up any resources in the network driver /* free up any resources in the network driver
@ -8697,17 +8674,11 @@ static int qemuStringToArgvEnv(const char *args,
if (!next) if (!next)
next = strchr(curr, '\n'); next = strchr(curr, '\n');
if (next) { if (VIR_STRNDUP(arg, curr, next ? next - curr : strlen(curr)) < 0)
arg = strndup(curr, next-curr); goto error;
if (*next == '\'' ||
*next == '"')
next++;
} else {
arg = strdup(curr);
}
if (!arg) if (next && (*next == '\'' || *next == '"'))
goto no_memory; next++;
if (argalloc == argcount) { if (argalloc == argcount) {
if (VIR_REALLOC_N(arglist, argalloc+10) < 0) { if (VIR_REALLOC_N(arglist, argalloc+10) < 0) {
@ -8758,13 +8729,14 @@ static int qemuStringToArgvEnv(const char *args,
return 0; return 0;
no_memory: no_memory:
virReportOOMError();
error:
for (i = 0; progenv && progenv[i]; i++) for (i = 0; progenv && progenv[i]; i++)
VIR_FREE(progenv[i]); VIR_FREE(progenv[i]);
VIR_FREE(progenv); VIR_FREE(progenv);
for (i = 0; i < argcount; i++) for (i = 0; i < argcount; i++)
VIR_FREE(arglist[i]); VIR_FREE(arglist[i]);
VIR_FREE(arglist); VIR_FREE(arglist);
virReportOOMError();
return -1; return -1;
} }
@ -8838,14 +8810,14 @@ qemuParseKeywords(const char *str,
separator = endmark; separator = endmark;
} }
if (!(keyword = strndup(start, separator - start))) if (VIR_STRNDUP(keyword, start, separator - start) < 0)
goto no_memory; goto error;
if (separator < endmark) { if (separator < endmark) {
separator++; separator++;
if (!(value = strndup(separator, endmark - separator))) { if (VIR_STRNDUP(value, separator, endmark - separator) < 0) {
VIR_FREE(keyword); VIR_FREE(keyword);
goto no_memory; goto error;
} }
if (strchr(value, ',')) { if (strchr(value, ',')) {
char *p = strchr(value, ',') + 1; char *p = strchr(value, ',') + 1;
@ -8949,11 +8921,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD;
def->src = strdup(p + strlen("rbd:")); if (VIR_STRDUP(def->src, p + strlen("rbd:")) < 0)
if (!def->src) {
virReportOOMError();
goto error; goto error;
}
/* old-style CEPH_ARGS env variable is parsed later */ /* old-style CEPH_ARGS env variable is parsed later */
if (!old_style_ceph_args && qemuParseRBDString(def) < 0) if (!old_style_ceph_args && qemuParseRBDString(def) < 0)
goto cleanup; goto cleanup;
@ -8978,11 +8947,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG;
def->src = strdup(p + strlen("sheepdog:")); if (VIR_STRDUP(def->src, p + strlen("sheepdog:")) < 0)
if (!def->src) {
virReportOOMError();
goto error; goto error;
}
/* def->src must be [vdiname] or [host]:[port]:[vdiname] */ /* def->src must be [vdiname] or [host]:[port]:[vdiname] */
port = strchr(def->src, ':'); port = strchr(def->src, ':');
@ -9001,18 +8967,12 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
} }
def->nhosts = 1; def->nhosts = 1;
def->hosts->name = def->src; def->hosts->name = def->src;
def->hosts->port = strdup(port); if (VIR_STRDUP(def->hosts->port, port) < 0)
if (!def->hosts->port) {
virReportOOMError();
goto error; goto error;
}
def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
def->hosts->socket = NULL; def->hosts->socket = NULL;
def->src = strdup(vdi); if (VIR_STRDUP(def->src, vdi) < 0)
if (!def->src) {
virReportOOMError();
goto error; goto error;
}
} }
VIR_FREE(p); VIR_FREE(p);
@ -9037,11 +8997,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
} else if (STREQ(values[i], "floppy")) } else if (STREQ(values[i], "floppy"))
def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
} else if (STREQ(keywords[i], "format")) { } else if (STREQ(keywords[i], "format")) {
def->driverName = strdup("qemu"); if (VIR_STRDUP(def->driverName, "qemu") < 0)
if (!def->driverName) {
virReportOOMError();
goto error; goto error;
}
def->format = virStorageFileFormatTypeFromString(values[i]); def->format = virStorageFileFormatTypeFromString(values[i]);
} else if (STREQ(keywords[i], "cache")) { } else if (STREQ(keywords[i], "cache")) {
if (STREQ(values[i], "off") || if (STREQ(values[i], "off") ||
@ -9181,21 +9138,19 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
} }
if (def->bus == VIR_DOMAIN_DISK_BUS_IDE) { if (def->bus == VIR_DOMAIN_DISK_BUS_IDE) {
def->dst = strdup("hda"); ignore_value(VIR_STRDUP(def->dst, "hda"));
} else if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) { } else if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
def->dst = strdup("sda"); ignore_value(VIR_STRDUP(def->dst, "sda"));
} else if (def->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { } else if (def->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
def->dst = strdup("vda"); ignore_value(VIR_STRDUP(def->dst, "vda"));
} else if (def->bus == VIR_DOMAIN_DISK_BUS_XEN) { } else if (def->bus == VIR_DOMAIN_DISK_BUS_XEN) {
def->dst = strdup("xvda"); ignore_value(VIR_STRDUP(def->dst, "xvda"));
} else { } else {
def->dst = strdup("hda"); ignore_value(VIR_STRDUP(def->dst, "hda"));
} }
if (!def->dst) { if (!def->dst)
virReportOOMError();
goto error; goto error;
}
if (STREQ(def->dst, "xvda")) if (STREQ(def->dst, "xvda"))
def->dst[3] = 'a' + idx; def->dst[3] = 'a' + idx;
else else
@ -9547,14 +9502,12 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
source->type = VIR_DOMAIN_CHR_TYPE_PTY; source->type = VIR_DOMAIN_CHR_TYPE_PTY;
} else if (STRPREFIX(val, "file:")) { } else if (STRPREFIX(val, "file:")) {
source->type = VIR_DOMAIN_CHR_TYPE_FILE; source->type = VIR_DOMAIN_CHR_TYPE_FILE;
source->data.file.path = strdup(val+strlen("file:")); if (VIR_STRDUP(source->data.file.path, val + strlen("file:")) < 0)
if (!source->data.file.path) goto error;
goto no_memory;
} else if (STRPREFIX(val, "pipe:")) { } else if (STRPREFIX(val, "pipe:")) {
source->type = VIR_DOMAIN_CHR_TYPE_PIPE; source->type = VIR_DOMAIN_CHR_TYPE_PIPE;
source->data.file.path = strdup(val+strlen("pipe:")); if (VIR_STRDUP(source->data.file.path, val + strlen("pipe:")) < 0)
if (!source->data.file.path) goto error;
goto no_memory;
} else if (STREQ(val, "stdio")) { } else if (STREQ(val, "stdio")) {
source->type = VIR_DOMAIN_CHR_TYPE_STDIO; source->type = VIR_DOMAIN_CHR_TYPE_STDIO;
} else if (STRPREFIX(val, "udp:")) { } else if (STRPREFIX(val, "udp:")) {
@ -9565,40 +9518,29 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
host2 = svc1 ? strchr(svc1, '@') : NULL; host2 = svc1 ? strchr(svc1, '@') : NULL;
svc2 = host2 ? strchr(host2, ':') : NULL; svc2 = host2 ? strchr(host2, ':') : NULL;
if (svc1 && (svc1 != val)) { if (svc1 && svc1 != val &&
source->data.udp.connectHost = strndup(val, svc1-val); VIR_STRNDUP(source->data.udp.connectHost, val, svc1 - val) < 0)
goto error;
if (!source->data.udp.connectHost)
goto no_memory;
}
if (svc1) { if (svc1) {
svc1++; svc1++;
if (host2) if (VIR_STRNDUP(source->data.udp.connectService, svc1,
source->data.udp.connectService = strndup(svc1, host2-svc1); host2 ? host2 - svc1 : strlen(svc1)) < 0)
else goto error;
source->data.udp.connectService = strdup(svc1);
if (!source->data.udp.connectService)
goto no_memory;
} }
if (host2) { if (host2) {
host2++; host2++;
if (svc2 && (svc2 != host2)) { if (svc2 && svc2 != host2 &&
source->data.udp.bindHost = strndup(host2, svc2-host2); VIR_STRNDUP(source->data.udp.bindHost, host2, svc2 - host2) < 0)
goto no_memory;
if (!source->data.udp.bindHost)
goto no_memory;
}
} }
if (svc2) { if (svc2) {
svc2++; svc2++;
if (STRNEQ(svc2, "0")) { if (STRNEQ(svc2, "0")) {
source->data.udp.bindService = strdup(svc2); if (VIR_STRDUP(source->data.udp.bindService, svc2) < 0)
if (!source->data.udp.bindService) goto error;
goto no_memory;
} }
} }
} else if (STRPREFIX(val, "tcp:") || } else if (STRPREFIX(val, "tcp:") ||
@ -9621,37 +9563,25 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
if (opt && strstr(opt, "server")) if (opt && strstr(opt, "server"))
source->data.tcp.listen = true; source->data.tcp.listen = true;
source->data.tcp.host = strndup(val, svc-val); if (VIR_STRNDUP(source->data.tcp.host, val, svc - val) < 0)
if (!source->data.tcp.host) goto error;
goto no_memory;
svc++; svc++;
if (opt) { if (VIR_STRNDUP(source->data.tcp.service, svc,
source->data.tcp.service = strndup(svc, opt-svc); opt ? opt - svc : strlen(svc)) < 0)
} else { goto error;
source->data.tcp.service = strdup(svc);
}
if (!source->data.tcp.service)
goto no_memory;
} else if (STRPREFIX(val, "unix:")) { } else if (STRPREFIX(val, "unix:")) {
const char *opt; const char *opt;
val += strlen("unix:"); val += strlen("unix:");
opt = strchr(val, ','); opt = strchr(val, ',');
source->type = VIR_DOMAIN_CHR_TYPE_UNIX; source->type = VIR_DOMAIN_CHR_TYPE_UNIX;
if (opt) { if (VIR_STRNDUP(source->data.nix.path, val,
if (strstr(opt, "listen")) opt ? opt - val : strlen(val)) < 0)
source->data.nix.listen = true; goto error;
source->data.nix.path = strndup(val, opt-val);
} else {
source->data.nix.path = strdup(val);
}
if (!source->data.nix.path)
goto no_memory;
} else if (STRPREFIX(val, "/dev")) { } else if (STRPREFIX(val, "/dev")) {
source->type = VIR_DOMAIN_CHR_TYPE_DEV; source->type = VIR_DOMAIN_CHR_TYPE_DEV;
source->data.file.path = strdup(val); if (VIR_STRDUP(source->data.file.path, val) < 0)
if (!source->data.file.path) goto error;
goto no_memory;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown character device syntax %s"), val); _("unknown character device syntax %s"), val);
@ -9704,13 +9634,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
next++; next++;
if (p == val) { if (p == val) {
if (next) if (VIR_STRNDUP(model, p, next ? next - p - 1 : strlen(p)) < 0)
model = strndup(p, next - p - 1); goto error;
else
model = strdup(p);
if (!model)
goto no_memory;
if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) { if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
if (!(cpu = qemuInitGuestCPU(dom))) if (!(cpu = qemuInitGuestCPU(dom)))
@ -9733,13 +9658,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
if (*p == '\0' || *p == ',') if (*p == '\0' || *p == ',')
goto syntax; goto syntax;
if (next) if (VIR_STRNDUP(feature, p, next ? next - p - 1 : strlen(p)) < 0)
feature = strndup(p, next - p - 1); goto error;
else
feature = strdup(p);
if (!feature)
goto no_memory;
if (STREQ(feature, "kvmclock")) { if (STREQ(feature, "kvmclock")) {
bool present = (policy == VIR_CPU_FEATURE_REQUIRE); bool present = (policy == VIR_CPU_FEATURE_REQUIRE);
@ -9797,13 +9717,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
if (*p == '\0' || *p == ',') if (*p == '\0' || *p == ',')
goto syntax; goto syntax;
if (next) if (VIR_STRNDUP(feature, p, next ? next - p - 1 : strlen(p)) < 0)
feature = strndup(p, next - p - 1); goto error;
else
feature = strdup(p);
if (!feature)
goto no_memory;
dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV); dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV);
@ -10021,8 +9936,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY; def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY;
def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY; def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY;
def->virtType = VIR_DOMAIN_VIRT_QEMU; def->virtType = VIR_DOMAIN_VIRT_QEMU;
if (!(def->emulator = strdup(progargv[0]))) if (VIR_STRDUP(def->emulator, progargv[0]) < 0)
goto no_memory; goto error;
if (strstr(def->emulator, "kvm")) { if (strstr(def->emulator, "kvm")) {
def->virtType = VIR_DOMAIN_VIRT_KVM; def->virtType = VIR_DOMAIN_VIRT_KVM;
@ -10032,12 +9947,12 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
if (strstr(def->emulator, "xenner")) { if (strstr(def->emulator, "xenner")) {
def->virtType = VIR_DOMAIN_VIRT_KVM; def->virtType = VIR_DOMAIN_VIRT_KVM;
def->os.type = strdup("xen"); if (VIR_STRDUP(def->os.type, "xen") < 0)
goto error;
} else { } else {
def->os.type = strdup("hvm"); if (VIR_STRDUP(def->os.type, "hvm") < 0)
goto error;
} }
if (!def->os.type)
goto no_memory;
if (STRPREFIX(def->emulator, "qemu")) if (STRPREFIX(def->emulator, "qemu"))
path = def->emulator; path = def->emulator;
@ -10100,10 +10015,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
if (STRPREFIX(val, "unix:")) { if (STRPREFIX(val, "unix:")) {
/* -vnc unix:/some/big/path */ /* -vnc unix:/some/big/path */
vnc->data.vnc.socket = strdup(val + 5); if (VIR_STRDUP(vnc->data.vnc.socket, val + 5) < 0) {
if (!vnc->data.vnc.socket) {
virDomainGraphicsDefFree(vnc); virDomainGraphicsDefFree(vnc);
goto no_memory; goto error;
} }
} else { } else {
/* /*
@ -10143,10 +10057,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
} }
if (*opts == ',') { if (*opts == ',') {
char *orig_opts = strdup(opts + 1); char *orig_opts;
if (!orig_opts) {
if (VIR_STRDUP(orig_opts, opts + 1) < 0) {
virDomainGraphicsDefFree(vnc); virDomainGraphicsDefFree(vnc);
goto no_memory; goto error;
} }
opts = orig_opts; opts = orig_opts;
@ -10265,9 +10180,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
if (STREQ(arg, "-cdrom")) { if (STREQ(arg, "-cdrom")) {
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
disk->dst = strdup("hdc"); if (VIR_STRDUP(disk->dst, "hdc") < 0)
if (!disk->dst) goto error;
goto no_memory;
disk->readonly = true; disk->readonly = true;
} else { } else {
if (STRPREFIX(arg, "-fd")) { if (STRPREFIX(arg, "-fd")) {
@ -10280,13 +10194,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
else else
disk->bus = VIR_DOMAIN_DISK_BUS_SCSI; disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
} }
disk->dst = strdup(arg + 1); if (VIR_STRDUP(disk->dst, arg + 1) < 0)
if (!disk->dst) goto error;
goto no_memory;
} }
disk->src = strdup(val); if (VIR_STRDUP(disk->src, val) < 0)
if (!disk->src) goto error;
goto no_memory;
if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
char *port; char *port;
@ -10319,12 +10231,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
goto no_memory; goto no_memory;
disk->nhosts = 1; disk->nhosts = 1;
disk->hosts->name = disk->src; disk->hosts->name = disk->src;
disk->hosts->port = strdup(port); if (VIR_STRDUP(disk->hosts->port, port) < 0)
if (!disk->hosts->port) goto error;
goto no_memory; if (VIR_STRDUP(disk->src, vdi) < 0)
disk->src = strdup(vdi); goto error;
if (!disk->src)
goto no_memory;
} }
break; break;
case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER:
@ -10371,24 +10281,24 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
} else if (STREQ(arg, "-kernel")) { } else if (STREQ(arg, "-kernel")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.kernel = strdup(val))) if (VIR_STRDUP(def->os.kernel, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-bios")) { } else if (STREQ(arg, "-bios")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.loader = strdup(val))) if (VIR_STRDUP(def->os.loader, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-initrd")) { } else if (STREQ(arg, "-initrd")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.initrd = strdup(val))) if (VIR_STRDUP(def->os.initrd, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-append")) { } else if (STREQ(arg, "-append")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.cmdline = strdup(val))) if (VIR_STRDUP(def->os.cmdline, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-dtb")) { } else if (STREQ(arg, "-dtb")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.dtb = strdup(val))) if (VIR_STRDUP(def->os.dtb, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-boot")) { } else if (STREQ(arg, "-boot")) {
const char *token = NULL; const char *token = NULL;
WANT_VALUE(); WANT_VALUE();
@ -10432,11 +10342,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
WANT_VALUE(); WANT_VALUE();
process = strstr(val, ",process="); process = strstr(val, ",process=");
if (process == NULL) { if (process == NULL) {
if (!(def->name = strdup(val))) if (VIR_STRDUP(def->name, val) < 0)
goto no_memory; goto error;
} else { } else {
if (!(def->name = strndup(val, process - val))) if (VIR_STRNDUP(def->name, val, process - val) < 0)
goto no_memory; goto error;
} }
if (STREQ(def->name, "")) if (STREQ(def->name, ""))
VIR_FREE(def->name); VIR_FREE(def->name);
@ -10446,11 +10356,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
WANT_VALUE(); WANT_VALUE();
params = strchr(val, ','); params = strchr(val, ',');
if (params == NULL) { if (params == NULL) {
if (!(def->os.machine = strdup(val))) if (VIR_STRDUP(def->os.machine, val) < 0)
goto no_memory; goto error;
} else { } else {
if (!(def->os.machine = strndup(val, params - val))) if (VIR_STRNDUP(def->os.machine, val, params - val) < 0)
goto no_memory; goto error;
while (params++) { while (params++) {
/* prepared for more "-machine" parameters */ /* prepared for more "-machine" parameters */
@ -10459,11 +10369,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
if (STRPREFIX(tmp, "dump-guest-core=")) { if (STRPREFIX(tmp, "dump-guest-core=")) {
tmp += strlen("dump-guest-core="); tmp += strlen("dump-guest-core=");
if (params) { if (params && VIR_STRNDUP(tmp, tmp, params - tmp) < 0)
tmp = strndup(tmp, params - tmp); goto error;
if (tmp == NULL)
goto no_memory;
}
def->mem.dump_core = virDomainMemDumpTypeFromString(tmp); def->mem.dump_core = virDomainMemDumpTypeFromString(tmp);
if (def->mem.dump_core <= 0) if (def->mem.dump_core <= 0)
def->mem.dump_core = VIR_DOMAIN_MEM_DUMP_DEFAULT; def->mem.dump_core = VIR_DOMAIN_MEM_DUMP_DEFAULT;
@ -10534,17 +10441,17 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
} else if (STRPREFIX(val, "disk:")) { } else if (STRPREFIX(val, "disk:")) {
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto no_memory;
disk->src = strdup(val + strlen("disk:")); if (VIR_STRDUP(disk->src, val + strlen("disk:")) < 0)
if (!disk->src) goto error;
goto no_memory;
if (STRPREFIX(disk->src, "/dev/")) if (STRPREFIX(disk->src, "/dev/"))
disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK; disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
else else
disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
disk->bus = VIR_DOMAIN_DISK_BUS_USB; disk->bus = VIR_DOMAIN_DISK_BUS_USB;
if (!(disk->dst = strdup("sda")) || if (VIR_STRDUP(disk->dst, "sda") < 0)
VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) goto error;
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
goto no_memory; goto no_memory;
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
disk = NULL; disk = NULL;
@ -10646,9 +10553,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
def->watchdog->action = action; def->watchdog->action = action;
} else if (STREQ(arg, "-bootloader")) { } else if (STREQ(arg, "-bootloader")) {
WANT_VALUE(); WANT_VALUE();
def->os.bootloader = strdup(val); if (VIR_STRDUP(def->os.bootloader, val) < 0)
if (!def->os.bootloader) goto error;
goto no_memory;
} else if (STREQ(arg, "-vmwarevga")) { } else if (STREQ(arg, "-vmwarevga")) {
video = VIR_DOMAIN_VIDEO_TYPE_VMVGA; video = VIR_DOMAIN_VIDEO_TYPE_VMVGA;
} else if (STREQ(arg, "-std-vga")) { } else if (STREQ(arg, "-std-vga")) {
@ -10681,8 +10587,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
} else if (STREQ(arg, "-pidfile")) { } else if (STREQ(arg, "-pidfile")) {
WANT_VALUE(); WANT_VALUE();
if (pidfile) if (pidfile)
if (!(*pidfile = strdup(val))) if (VIR_STRDUP(*pidfile, val) < 0)
goto no_memory; goto error;
} else if (STREQ(arg, "-incoming")) { } else if (STREQ(arg, "-incoming")) {
WANT_VALUE(); WANT_VALUE();
/* ignore, used via restore/migrate APIs */ /* ignore, used via restore/migrate APIs */
@ -10764,9 +10670,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
arg); arg);
if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0) if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0)
goto no_memory; goto no_memory;
cmd->args[cmd->num_args] = strdup(arg); if (VIR_STRDUP(cmd->args[cmd->num_args], arg) < 0)
if (cmd->args[cmd->num_args] == NULL) goto error;
goto no_memory;
cmd->num_args++; cmd->num_args++;
} }
} }
@ -10795,9 +10700,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
_("could not parse CEPH_ARGS '%s'"), ceph_args); _("could not parse CEPH_ARGS '%s'"), ceph_args);
goto error; goto error;
} }
hosts = strdup(strchr(ceph_args, ' ') + 1); if (VIR_STRDUP(hosts, strchr(ceph_args, ' ') + 1) < 0)
if (!hosts) goto error;
goto no_memory;
first_rbd_disk->nhosts = 0; first_rbd_disk->nhosts = 0;
token = strtok_r(hosts, ",", &saveptr); token = strtok_r(hosts, ",", &saveptr);
while (token != NULL) { while (token != NULL) {
@ -10808,17 +10712,16 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
port = strchr(token, ':'); port = strchr(token, ':');
if (port) { if (port) {
*port++ = '\0'; *port++ = '\0';
port = strdup(port); if (VIR_STRDUP(port, port) < 0) {
if (!port) {
VIR_FREE(hosts); VIR_FREE(hosts);
goto no_memory; goto error;
} }
} }
first_rbd_disk->hosts[first_rbd_disk->nhosts].port = port; first_rbd_disk->hosts[first_rbd_disk->nhosts].port = port;
first_rbd_disk->hosts[first_rbd_disk->nhosts].name = strdup(token); if (VIR_STRDUP(first_rbd_disk->hosts[first_rbd_disk->nhosts].name,
if (!first_rbd_disk->hosts[first_rbd_disk->nhosts].name) { token) < 0) {
VIR_FREE(hosts); VIR_FREE(hosts);
goto no_memory; goto error;
} }
first_rbd_disk->hosts[first_rbd_disk->nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; first_rbd_disk->hosts[first_rbd_disk->nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
first_rbd_disk->hosts[first_rbd_disk->nhosts].socket = NULL; first_rbd_disk->hosts[first_rbd_disk->nhosts].socket = NULL;
@ -10842,8 +10745,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
def->os.arch, def->os.arch,
virDomainVirtTypeToString(def->virtType)); virDomainVirtTypeToString(def->virtType));
if (defaultMachine != NULL) if (defaultMachine != NULL)
if (!(def->os.machine = strdup(defaultMachine))) if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
goto no_memory; goto error;
} }
if (!nographics && def->ngraphics == 0) { if (!nographics && def->ngraphics == 0) {
@ -10854,15 +10757,13 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
goto no_memory; goto no_memory;
sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
sdl->data.sdl.fullscreen = fullscreen; sdl->data.sdl.fullscreen = fullscreen;
if (display && if (VIR_STRDUP(sdl->data.sdl.display, display) < 0) {
!(sdl->data.sdl.display = strdup(display))) {
VIR_FREE(sdl); VIR_FREE(sdl);
goto no_memory; goto error;
} }
if (xauth && if (VIR_STRDUP(sdl->data.sdl.xauth, xauth) < 0) {
!(sdl->data.sdl.xauth = strdup(xauth))) {
VIR_FREE(sdl); VIR_FREE(sdl);
goto no_memory; goto error;
} }
if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) { if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) {
@ -10979,7 +10880,7 @@ static int qemuParseProcFileStrings(int pid_value,
ssize_t len; ssize_t len;
char *tmp; char *tmp;
size_t nstr = 0; size_t nstr = 0;
const char **str = NULL; char **str = NULL;
int i; int i;
if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) { if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) {
@ -10997,10 +10898,8 @@ static int qemuParseProcFileStrings(int pid_value,
goto cleanup; goto cleanup;
} }
if (!(str[nstr-1] = strdup(tmp))) { if (VIR_STRDUP(str[nstr-1], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* Skip arg */ /* Skip arg */
tmp += strlen(tmp); tmp += strlen(tmp);
/* Skip \0 separator */ /* Skip \0 separator */
@ -11015,7 +10914,7 @@ static int qemuParseProcFileStrings(int pid_value,
str[nstr-1] = NULL; str[nstr-1] = NULL;
ret = nstr-1; ret = nstr-1;
*list = str; *list = (const char **) str;
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {

View File

@ -140,8 +140,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
"%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0)
goto no_memory; goto no_memory;
if ((cfg->configBaseDir = strdup(SYSCONFDIR "/libvirt")) == NULL) if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0)
goto no_memory; goto error;
if (virAsprintf(&cfg->stateDir, if (virAsprintf(&cfg->stateDir,
"%s/run/libvirt/qemu", LOCALSTATEDIR) < 0) "%s/run/libvirt/qemu", LOCALSTATEDIR) < 0)
@ -210,19 +210,17 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
goto no_memory; goto no_memory;
if (!(cfg->vncListen = strdup("127.0.0.1"))) if (VIR_STRDUP(cfg->vncListen, "127.0.0.1") < 0)
goto no_memory; goto error;
if (!(cfg->vncTLSx509certdir if (VIR_STRDUP(cfg->vncTLSx509certdir, SYSCONFDIR "/pki/libvirt-vnc") < 0)
= strdup(SYSCONFDIR "/pki/libvirt-vnc"))) goto error;
goto no_memory;
if (!(cfg->spiceListen = strdup("127.0.0.1"))) if (VIR_STRDUP(cfg->spiceListen, "127.0.0.1") < 0)
goto no_memory; goto error;
if (!(cfg->spiceTLSx509certdir if (VIR_STRDUP(cfg->spiceTLSx509certdir , SYSCONFDIR "/pki/libvirt-spice") < 0)
= strdup(SYSCONFDIR "/pki/libvirt-spice"))) goto error;
goto no_memory;
cfg->remotePortMin = QEMU_REMOTE_PORT_MIN; cfg->remotePortMin = QEMU_REMOTE_PORT_MIN;
cfg->remotePortMax = QEMU_REMOTE_PORT_MAX; cfg->remotePortMax = QEMU_REMOTE_PORT_MAX;
@ -243,8 +241,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
} }
} }
#endif #endif
if (!(cfg->bridgeHelperName = strdup("/usr/libexec/qemu-bridge-helper"))) if (VIR_STRDUP(cfg->bridgeHelperName, "/usr/libexec/qemu-bridge-helper") < 0)
goto no_memory; goto error;
cfg->clearEmulatorCapabilities = true; cfg->clearEmulatorCapabilities = true;
@ -350,8 +348,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
CHECK_TYPE(NAME, VIR_CONF_STRING); \ CHECK_TYPE(NAME, VIR_CONF_STRING); \
if (p && p->str) { \ if (p && p->str) { \
VIR_FREE(VAR); \ VIR_FREE(VAR); \
if (!(VAR = strdup(p->str))) \ if (VIR_STRDUP(VAR, p->str) < 0) \
goto no_memory; \ goto cleanup; \
} }
GET_VALUE_BOOL("vnc_auto_unix_socket", cfg->vncAutoUnixSocket); GET_VALUE_BOOL("vnc_auto_unix_socket", cfg->vncAutoUnixSocket);
@ -382,16 +380,17 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
goto no_memory; goto no_memory;
for (i = 0, pp = p->list; pp; i++, pp = pp->next) { for (i = 0, pp = p->list; pp; i++, pp = pp->next) {
if (!(cfg->securityDriverNames[i] = strdup(pp->str))) if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0)
goto no_memory; goto cleanup;
} }
cfg->securityDriverNames[len] = NULL; cfg->securityDriverNames[len] = NULL;
} else { } else {
CHECK_TYPE("security_driver", VIR_CONF_STRING); CHECK_TYPE("security_driver", VIR_CONF_STRING);
if (p && p->str) { if (p && p->str) {
if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0 || if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0)
!(cfg->securityDriverNames[0] = strdup(p->str)))
goto no_memory; goto no_memory;
if (VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0)
goto cleanup;
cfg->securityDriverNames[1] = NULL; cfg->securityDriverNames[1] = NULL;
} }
@ -518,8 +517,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
"list of strings")); "list of strings"));
goto cleanup; goto cleanup;
} }
if (!(cfg->cgroupDeviceACL[i] = strdup(pp->str))) if (VIR_STRDUP(cfg->cgroupDeviceACL[i], pp->str) < 0)
goto no_memory; goto cleanup;
} }
cfg->cgroupDeviceACL[i] = NULL; cfg->cgroupDeviceACL[i] = NULL;
} }
@ -618,10 +617,9 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
for (i = 0; sec_managers[i]; i++) { for (i = 0; sec_managers[i]; i++) {
doi = virSecurityManagerGetDOI(sec_managers[i]); doi = virSecurityManagerGetDOI(sec_managers[i]);
model = virSecurityManagerGetModel(sec_managers[i]); model = virSecurityManagerGetModel(sec_managers[i]);
if (!(caps->host.secModels[i].model = strdup(model))) if (VIR_STRDUP(caps->host.secModels[i].model, model) < 0 ||
goto no_memory; VIR_STRDUP(caps->host.secModels[i].doi, doi) < 0)
if (!(caps->host.secModels[i].doi = strdup(doi))) goto error;
goto no_memory;
VIR_DEBUG("Initialized caps for security driver \"%s\" with " VIR_DEBUG("Initialized caps for security driver \"%s\" with "
"DOI \"%s\"", model, doi); "DOI \"%s\"", model, doi);
} }
@ -1140,10 +1138,8 @@ qemuSharedDeviceEntryCopy(const qemuSharedDeviceEntryPtr entry)
} }
for (i = 0; i < entry->ref; i++) { for (i = 0; i < entry->ref; i++) {
if (!(ret->domains[i] = strdup(entry->domains[i]))) { if (VIR_STRDUP(ret->domains[i], entry->domains[i]) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret->ref++; ret->ref++;
} }
@ -1237,8 +1233,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
if (!(new_entry = qemuSharedDeviceEntryCopy(entry))) if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
goto cleanup; goto cleanup;
if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) || if (VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0 ||
!(new_entry->domains[new_entry->ref - 1] = strdup(name))) { VIR_STRDUP(new_entry->domains[new_entry->ref - 1], name) < 0) {
qemuSharedDeviceEntryFree(new_entry, NULL); qemuSharedDeviceEntryFree(new_entry, NULL);
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
@ -1249,9 +1245,9 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
} else { } else {
if ((VIR_ALLOC(entry) < 0) || if (VIR_ALLOC(entry) < 0 ||
(VIR_ALLOC_N(entry->domains, 1) < 0) || VIR_ALLOC_N(entry->domains, 1) < 0 ||
!(entry->domains[0] = strdup(name))) { VIR_STRDUP(entry->domains[0], name) < 0) {
qemuSharedDeviceEntryFree(entry, NULL); qemuSharedDeviceEntryFree(entry, NULL);
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;

View File

@ -727,14 +727,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
if (dev->type == VIR_DOMAIN_DEVICE_NET && if (dev->type == VIR_DOMAIN_DEVICE_NET &&
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
!dev->data.net->model) { !dev->data.net->model) {
if (def->os.arch == VIR_ARCH_S390 || if (VIR_STRDUP(dev->data.net->model,
def->os.arch == VIR_ARCH_S390X) def->os.arch == VIR_ARCH_S390 ||
dev->data.net->model = strdup("virtio"); def->os.arch == VIR_ARCH_S390X ? "virtio" : "rtl8139") < 0)
else goto cleanup;
dev->data.net->model = strdup("rtl8139");
if (!dev->data.net->model)
goto no_memory;
} }
/* set default disk types and drivers */ /* set default disk types and drivers */
@ -758,8 +754,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
} else { } else {
/* default driver if probing is forbidden */ /* default driver if probing is forbidden */
if (!disk->driverName && if (!disk->driverName &&
!(disk->driverName = strdup("qemu"))) VIR_STRDUP(disk->driverName, "qemu") < 0)
goto no_memory; goto cleanup;
/* default disk format for drives */ /* default disk format for drives */
if (disk->format == VIR_STORAGE_FILE_NONE && if (disk->format == VIR_STORAGE_FILE_NONE &&
@ -801,8 +797,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
if (virAsprintf(&dev->data.chr->source.data.nix.path, if (virAsprintf(&dev->data.chr->source.data.nix.path,
"%s/channel/target/%s.%s", "%s/channel/target/%s.%s",
cfg->libDir, def->name, cfg->libDir, def->name,
dev->data.chr->target.name) < 0) dev->data.chr->target.name) < 0) {
goto no_memory; virReportOOMError();
goto cleanup;
}
dev->data.chr->source.data.nix.listen = true; dev->data.chr->source.data.nix.listen = true;
} }
@ -811,10 +809,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
cleanup: cleanup:
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
no_memory:
virReportOOMError();
goto cleanup;
} }

View File

@ -1456,10 +1456,8 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
if (STRNEQ(canon, def->os.machine)) { if (STRNEQ(canon, def->os.machine)) {
char *tmp; char *tmp;
if (!(tmp = strdup(canon))) { if (VIR_STRDUP(tmp, canon) < 0)
virReportOOMError();
return -1; return -1;
}
VIR_FREE(def->os.machine); VIR_FREE(def->os.machine);
def->os.machine = tmp; def->os.machine = tmp;
} }
@ -2047,8 +2045,7 @@ static char *qemuDomainGetOSType(virDomainPtr dom) {
if (!(vm = qemuDomObjFromDomain(dom))) if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
if (!(type = strdup(vm->def->os.type))) ignore_value(VIR_STRDUP(type, vm->def->os.type));
virReportOOMError();
cleanup: cleanup:
if (vm) if (vm)
@ -3426,7 +3423,7 @@ qemuDomainScreenshot(virDomainPtr dom,
goto endjob; goto endjob;
} }
ret = strdup("image/x-portable-pixmap"); ignore_value(VIR_STRDUP(ret, "image/x-portable-pixmap"));
endjob: endjob:
VIR_FORCE_CLOSE(tmp_fd); VIR_FORCE_CLOSE(tmp_fd);
@ -5174,11 +5171,8 @@ static char *qemuConnectDomainXMLFromNative(virConnectPtr conn,
if (!def) if (!def)
goto cleanup; goto cleanup;
if (!def->name && if (!def->name && VIR_STRDUP(def->name, "unnamed") < 0)
!(def->name = strdup("unnamed"))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
xml = qemuDomainDefFormatXML(driver, def, VIR_DOMAIN_XML_INACTIVE); xml = qemuDomainDefFormatXML(driver, def, VIR_DOMAIN_XML_INACTIVE);
@ -5244,11 +5238,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) && if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
(brname = virDomainNetGetActualBridgeName(net))) { (brname = virDomainNetGetActualBridgeName(net))) {
char *brnamecopy = strdup(brname); char *brnamecopy;
if (!brnamecopy) { if (VIR_STRDUP(brnamecopy, brname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virDomainActualNetDefFree(net->data.network.actual); virDomainActualNetDefFree(net->data.network.actual);
@ -6923,9 +6915,7 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom,
*nparams = 5; *nparams = 5;
} }
ret = strdup("posix"); ignore_value(VIR_STRDUP(ret, "posix"));
if (!ret)
virReportOOMError();
cleanup: cleanup:
if (vm) if (vm)
@ -6983,11 +6973,8 @@ qemuDomainParseDeviceWeightStr(char *deviceWeightStr,
if (!p) if (!p)
goto error; goto error;
result[i].path = strndup(temp, p - temp); if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0)
if (!result[i].path) {
virReportOOMError();
goto cleanup; goto cleanup;
}
/* weight */ /* weight */
temp = p + 1; temp = p + 1;
@ -7351,13 +7338,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
} }
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s) { if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
param->value.s = strdup(""); goto cleanup;
if (!param->value.s) {
virReportOOMError();
goto cleanup;
}
}
param->type = VIR_TYPED_PARAM_STRING; param->type = VIR_TYPED_PARAM_STRING;
if (virStrcpyStatic(param->field, if (virStrcpyStatic(param->field,
VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) { VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) {
@ -7882,8 +7864,8 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
case 1: /* fill numa nodeset here */ case 1: /* fill numa nodeset here */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask); nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask);
if (!nodeset) if (!nodeset && VIR_STRDUP(nodeset, "") < 0)
nodeset = strdup(""); goto cleanup;
} else { } else {
rc = virCgroupGetCpusetMems(priv->cgroup, &nodeset); rc = virCgroupGetCpusetMems(priv->cgroup, &nodeset);
if (rc != 0) { if (rc != 0) {
@ -9560,10 +9542,8 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
if (dname) { if (dname) {
VIR_FREE(def->name); VIR_FREE(def->name);
if (!(def->name = strdup(dname))) { if (VIR_STRDUP(def->name, dname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = qemuMigrationPrepareTunnel(driver, dconn, ret = qemuMigrationPrepareTunnel(driver, dconn,
@ -9633,10 +9613,8 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
if (dname) { if (dname) {
VIR_FREE(def->name); VIR_FREE(def->name);
if (!(def->name = strdup(dname))) { if (VIR_STRDUP(def->name, dname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
/* Do not use cookies in v2 protocol, since the cookie /* Do not use cookies in v2 protocol, since the cookie
@ -9874,10 +9852,8 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
if (dname) { if (dname) {
VIR_FREE(def->name); VIR_FREE(def->name);
if (!(def->name = strdup(dname))) { if (VIR_STRDUP(def->name, dname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = qemuMigrationPrepareDirect(driver, dconn, ret = qemuMigrationPrepareDirect(driver, dconn,
@ -9939,10 +9915,8 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
if (dname) { if (dname) {
VIR_FREE(def->name); VIR_FREE(def->name);
if (!(def->name = strdup(dname))) { if (VIR_STRDUP(def->name, dname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = qemuMigrationPrepareTunnel(driver, dconn, ret = qemuMigrationPrepareTunnel(driver, dconn,
@ -10959,9 +10933,8 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
VIR_FREE(defdisk->src); VIR_FREE(defdisk->src);
if (!(defdisk->src = strdup(snapdisk->file))) { if (VIR_STRDUP(defdisk->src, snapdisk->file) < 0) {
/* we cannot rollback here in a sane way */ /* we cannot rollback here in a sane way */
virReportOOMError();
goto cleanup; goto cleanup;
} }
defdisk->format = snapdisk->format; defdisk->format = snapdisk->format;
@ -11250,9 +11223,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
} }
if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 || if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 ||
!(source = strdup(snap->file)) || VIR_STRDUP(source, snap->file) < 0 ||
(persistDisk && (persistDisk && VIR_STRDUP(persistSource, source) < 0)) {
!(persistSource = strdup(source)))) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
@ -11329,12 +11301,9 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
char *persistSource = NULL; char *persistSource = NULL;
struct stat st; struct stat st;
if (!(source = strdup(origdisk->src)) || if (VIR_STRDUP(source, origdisk->src) < 0 ||
(persistDisk && (persistDisk && VIR_STRDUP(persistSource, source) < 0))
!(persistSource = strdup(source)))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
qemuDomainPrepareDiskChainElement(driver, vm, disk, origdisk->src, qemuDomainPrepareDiskChainElement(driver, vm, disk, origdisk->src,
VIR_DISK_CHAIN_NO_ACCESS); VIR_DISK_CHAIN_NO_ACCESS);
@ -11938,13 +11907,9 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
if (update_current) if (update_current)
snap->def->current = true; snap->def->current = true;
if (vm->current_snapshot) { if (vm->current_snapshot) {
if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) { if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE) &&
snap->def->parent = strdup(vm->current_snapshot->def->name); VIR_STRDUP(snap->def->parent, vm->current_snapshot->def->name) < 0)
if (snap->def->parent == NULL) {
virReportOOMError();
goto cleanup; goto cleanup;
}
}
if (update_current) { if (update_current) {
vm->current_snapshot->def->current = false; vm->current_snapshot->def->current = false;
if (qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot, if (qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot,
@ -12723,14 +12688,10 @@ qemuDomainSnapshotReparentChildren(void *payload,
VIR_FREE(snap->def->parent); VIR_FREE(snap->def->parent);
snap->parent = rep->parent; snap->parent = rep->parent;
if (rep->parent->def) { if (rep->parent->def &&
snap->def->parent = strdup(rep->parent->def->name); VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
rep->err = -1;
if (snap->def->parent == NULL) { return;
virReportOOMError();
rep->err = -1;
return;
}
} }
if (!snap->sibling) if (!snap->sibling)
@ -13637,10 +13598,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path,
} }
if (!format && disk->mirrorFormat > 0) if (!format && disk->mirrorFormat > 0)
format = virStorageFileFormatTypeToString(disk->mirrorFormat); format = virStorageFileFormatTypeToString(disk->mirrorFormat);
if (!(mirror = strdup(dest))) { if (VIR_STRDUP(mirror, dest) < 0)
virReportOOMError();
goto endjob; goto endjob;
}
if (qemuDomainPrepareDiskChainElement(driver, vm, disk, dest, if (qemuDomainPrepareDiskChainElement(driver, vm, disk, dest,
VIR_DISK_CHAIN_READ_WRITE) < 0) { VIR_DISK_CHAIN_READ_WRITE) < 0) {
@ -14271,10 +14230,8 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
if (n == nerrors) if (n == nerrors)
break; break;
if (!(errors[n].disk = strdup(disk->dst))) { if (VIR_STRDUP(errors[n].disk, disk->dst) < 0)
virReportOOMError();
goto endjob; goto endjob;
}
errors[n].error = info->io_status; errors[n].error = info->io_status;
n++; n++;
} }
@ -14331,15 +14288,13 @@ qemuDomainSetMetadata(virDomainPtr dom,
switch ((virDomainMetadataType) type) { switch ((virDomainMetadataType) type) {
case VIR_DOMAIN_METADATA_DESCRIPTION: case VIR_DOMAIN_METADATA_DESCRIPTION:
VIR_FREE(vm->def->description); VIR_FREE(vm->def->description);
if (metadata && if (VIR_STRDUP(vm->def->description, metadata) < 0)
!(vm->def->description = strdup(metadata))) goto cleanup;
goto no_memory;
break; break;
case VIR_DOMAIN_METADATA_TITLE: case VIR_DOMAIN_METADATA_TITLE:
VIR_FREE(vm->def->title); VIR_FREE(vm->def->title);
if (metadata && if (VIR_STRDUP(vm->def->title, metadata) < 0)
!(vm->def->title = strdup(metadata))) goto cleanup;
goto no_memory;
break; break;
case VIR_DOMAIN_METADATA_ELEMENT: case VIR_DOMAIN_METADATA_ELEMENT:
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
@ -14359,15 +14314,13 @@ qemuDomainSetMetadata(virDomainPtr dom,
switch ((virDomainMetadataType) type) { switch ((virDomainMetadataType) type) {
case VIR_DOMAIN_METADATA_DESCRIPTION: case VIR_DOMAIN_METADATA_DESCRIPTION:
VIR_FREE(persistentDef->description); VIR_FREE(persistentDef->description);
if (metadata && if (VIR_STRDUP(persistentDef->description, metadata) < 0)
!(persistentDef->description = strdup(metadata))) goto cleanup;
goto no_memory;
break; break;
case VIR_DOMAIN_METADATA_TITLE: case VIR_DOMAIN_METADATA_TITLE:
VIR_FREE(persistentDef->title); VIR_FREE(persistentDef->title);
if (metadata && if (VIR_STRDUP(persistentDef->title, metadata) < 0)
!(persistentDef->title = strdup(metadata))) goto cleanup;
goto no_memory;
break; break;
case VIR_DOMAIN_METADATA_ELEMENT: case VIR_DOMAIN_METADATA_ELEMENT:
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
@ -14393,9 +14346,6 @@ cleanup:
virObjectUnref(caps); virObjectUnref(caps);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
no_memory:
virReportOOMError();
goto cleanup;
} }
static char * static char *
@ -14453,10 +14403,7 @@ qemuDomainGetMetadata(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
if (!(ret = strdup(field))) { ignore_value(VIR_STRDUP(ret, field));
virReportOOMError();
goto cleanup;
}
cleanup: cleanup:
if (vm) if (vm)

View File

@ -1411,10 +1411,8 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net)
goto cleanup; goto cleanup;
} }
/* we need a copy, not just a pointer to the original */ /* we need a copy, not just a pointer to the original */
if (!(brname = strdup(tmpbr))) { if (VIR_STRDUP(brname, tmpbr) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) { } else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
int active; int active;
virErrorPtr errobj; virErrorPtr errobj;
@ -1667,11 +1665,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
} }
/* ifname: check if it's set in newdev. If not, retain the autogenerated one */ /* ifname: check if it's set in newdev. If not, retain the autogenerated one */
if (!(newdev->ifname || if (!newdev->ifname && VIR_STRDUP(newdev->ifname, olddev->ifname) < 0)
(newdev->ifname = strdup(olddev->ifname)))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
if (STRNEQ_NULLABLE(olddev->ifname, newdev->ifname)) { if (STRNEQ_NULLABLE(olddev->ifname, newdev->ifname)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot modify network device tap name")); _("cannot modify network device tap name"));
@ -1696,11 +1691,9 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
/* grab alias from olddev if not set in newdev */ /* grab alias from olddev if not set in newdev */
if (!(newdev->info.alias || if (!newdev->info.alias &&
(newdev->info.alias = strdup(olddev->info.alias)))) { VIR_STRDUP(newdev->info.alias, olddev->info.alias) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (STRNEQ_NULLABLE(olddev->info.alias, newdev->info.alias)) { if (STRNEQ_NULLABLE(olddev->info.alias, newdev->info.alias)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot modify network device alias")); _("cannot modify network device alias"));

View File

@ -316,8 +316,8 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver,
goto error; goto error;
#endif #endif
} }
if (!(mig->listen = strdup(listenAddr))) if (VIR_STRDUP(mig->listen, listenAddr) < 0)
goto no_memory; goto error;
virObjectUnref(cfg); virObjectUnref(cfg);
return mig; return mig;
@ -400,8 +400,8 @@ qemuMigrationCookieNew(virDomainObjPtr dom)
name = priv->origname; name = priv->origname;
else else
name = dom->def->name; name = dom->def->name;
if (!(mig->name = strdup(name))) if (VIR_STRDUP(mig->name, name) < 0)
goto no_memory; goto error;
memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN); memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN);
if (!(mig->localHostname = virGetHostname())) if (!(mig->localHostname = virGetHostname()))
@ -460,15 +460,14 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
} }
if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) { if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) {
if (priv->lockState && if (VIR_STRDUP(mig->lockState, priv->lockState) < 0)
!(mig->lockState = strdup(priv->lockState)))
return -1; return -1;
} else { } else {
if (virDomainLockProcessInquire(driver->lockManager, dom, &mig->lockState) < 0) if (virDomainLockProcessInquire(driver->lockManager, dom, &mig->lockState) < 0)
return -1; return -1;
} }
if (!(mig->lockDriver = strdup(virLockManagerPluginGetName(driver->lockManager)))) { if (VIR_STRDUP(mig->lockDriver, virLockManagerPluginGetName(driver->lockManager)) < 0) {
VIR_FREE(mig->lockState); VIR_FREE(mig->lockState);
return -1; return -1;
} }
@ -2081,10 +2080,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
/* QEMU will be started with -incoming stdio /* QEMU will be started with -incoming stdio
* (which qemu_command might convert to exec:cat or fd:n) * (which qemu_command might convert to exec:cat or fd:n)
*/ */
if (!(migrateFrom = strdup("stdio"))) { if (VIR_STRDUP(migrateFrom, "stdio") < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} else { } else {
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
struct addrinfo *info = NULL; struct addrinfo *info = NULL;

View File

@ -201,11 +201,9 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
if (nl) { if (nl) {
int got = nl - (data + used); int got = nl - (data + used);
char *line = strndup(data + used, got); char *line;
if (!line) { if (VIR_STRNDUP(line, data + used, got) < 0)
virReportOOMError();
return -1; return -1;
}
used += got + strlen(LINE_ENDING); used += got + strlen(LINE_ENDING);
line[got] = '\0'; /* kill \n */ line[got] = '\0'; /* kill \n */
if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) { if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
@ -958,15 +956,9 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
if (reply_str) { if (reply_str) {
const char *data; const char *data;
if ((data = virJSONValueGetString(obj))) data = virJSONValueGetString(obj);
*reply_str = strdup(data); if (VIR_STRDUP(*reply_str, data ? data : "") < 0)
else
*reply_str = strdup("");
if (!*reply_str) {
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = 0; ret = 0;
@ -2946,11 +2938,9 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
} }
if (STRPREFIX(type, "pty:")) { if (STRPREFIX(type, "pty:")) {
char *path = strdup(type + strlen("pty:")); char *path;
if (!path) { if (VIR_STRDUP(path, type + strlen("pty:")) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virHashAddEntry(paths, id, path) < 0) { if (virHashAddEntry(paths, id, path) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
@ -3925,10 +3915,8 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
_("query-version reply was missing 'package' version")); _("query-version reply was missing 'package' version"));
goto cleanup; goto cleanup;
} }
if (!(*package = strdup(tmp))) { if (VIR_STRDUP(*package, tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = 0; ret = 0;
@ -4002,10 +3990,8 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(info->name = strdup(tmp))) { if (VIR_STRDUP(info->name, tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virJSONValueObjectHasKey(child, "is-default") && if (virJSONValueObjectHasKey(child, "is-default") &&
virJSONValueObjectGetBoolean(child, "is-default", &info->isDefault) < 0) { virJSONValueObjectGetBoolean(child, "is-default", &info->isDefault) < 0) {
@ -4020,10 +4006,8 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
_("query-machines reply has malformed 'alias' data")); _("query-machines reply has malformed 'alias' data"));
goto cleanup; goto cleanup;
} }
if (!(info->alias = strdup(tmp))) { if (VIR_STRDUP(info->alias, tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
} }
@ -4108,10 +4092,8 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(cpulist[i] = strdup(tmp))) { if (VIR_STRDUP(cpulist[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;
@ -4180,10 +4162,8 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(commandlist[i] = strdup(tmp))) { if (VIR_STRDUP(commandlist[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;
@ -4257,10 +4237,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(eventlist[i] = strdup(tmp))) { if (VIR_STRDUP(eventlist[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;
@ -4500,10 +4478,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(typelist[i] = strdup(tmp))) { if (VIR_STRDUP(typelist[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;
@ -4580,10 +4556,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (!(proplist[i] = strdup(tmp))) { if (VIR_STRDUP(proplist[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;
@ -4631,10 +4605,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
goto cleanup; goto cleanup;
} }
if (!(ret = strdup(arch))) { ignore_value(VIR_STRDUP(ret, arch));
virReportOOMError();
goto cleanup;
}
cleanup: cleanup:
virJSONValueFree(cmd); virJSONValueFree(cmd);
@ -4928,10 +4899,8 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
goto cleanup; goto cleanup;
} }
if (!(list[i] = strdup(tmp))) { if (VIR_STRDUP(list[i], tmp) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
ret = n; ret = n;

View File

@ -258,11 +258,8 @@ qemuMonitorTextCommandWithHandler(qemuMonitorPtr mon,
if (msg.rxBuffer) { if (msg.rxBuffer) {
*reply = msg.rxBuffer; *reply = msg.rxBuffer;
} else { } else {
*reply = strdup(""); if (VIR_STRDUP(*reply, "") < 0)
if (!*reply) {
virReportOOMError();
return -1; return -1;
}
} }
} }
@ -330,10 +327,8 @@ qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon,
/* Extra the path */ /* Extra the path */
pathStart += strlen(DISK_ENCRYPTION_PREFIX); pathStart += strlen(DISK_ENCRYPTION_PREFIX);
if (!(path = strndup(pathStart, pathEnd - pathStart))) { if (VIR_STRNDUP(path, pathStart, pathEnd - pathStart) < 0)
virReportOOMError();
return -1; return -1;
}
/* Fetch the disk password if possible */ /* Fetch the disk password if possible */
res = qemuMonitorGetDiskSecret(mon, res = qemuMonitorGetDiskSecret(mon,
@ -2283,11 +2278,9 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
/* Path is everything after needle to the end of the line */ /* Path is everything after needle to the end of the line */
*eol = '\0'; *eol = '\0';
char *path = strdup(needle + strlen(NEEDLE)); char *path;
if (path == NULL) { if (VIR_STRDUP(path, needle + strlen(NEEDLE)) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virHashAddEntry(paths, id, path) < 0) { if (virHashAddEntry(paths, id, path) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,

View File

@ -1000,16 +1000,16 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
if (VIR_ALLOC(localAddr) < 0) if (VIR_ALLOC(localAddr) < 0)
goto no_memory; goto no_memory;
localAddr->family = localFamily; localAddr->family = localFamily;
if (!(localAddr->service = strdup(localService)) || if (VIR_STRDUP(localAddr->service, localService) < 0 ||
!(localAddr->node = strdup(localNode))) VIR_STRDUP(localAddr->node, localNode) < 0)
goto no_memory; goto error;
if (VIR_ALLOC(remoteAddr) < 0) if (VIR_ALLOC(remoteAddr) < 0)
goto no_memory; goto no_memory;
remoteAddr->family = remoteFamily; remoteAddr->family = remoteFamily;
if (!(remoteAddr->service = strdup(remoteService)) || if (VIR_STRDUP(remoteAddr->service, remoteService) < 0 ||
!(remoteAddr->node = strdup(remoteNode))) VIR_STRDUP(remoteAddr->node, remoteNode) < 0)
goto no_memory; goto error;
if (VIR_ALLOC(subject) < 0) if (VIR_ALLOC(subject) < 0)
goto no_memory; goto no_memory;
@ -1017,17 +1017,17 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
goto no_memory; goto no_memory;
subject->nidentity++; subject->nidentity++;
if (!(subject->identities[subject->nidentity-1].type = strdup("x509dname")) || if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "x509dname") < 0 ||
!(subject->identities[subject->nidentity-1].name = strdup(x509dname))) VIR_STRDUP(subject->identities[subject->nidentity-1].name, x509dname) < 0)
goto no_memory; goto error;
} }
if (saslUsername) { if (saslUsername) {
if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
goto no_memory; goto no_memory;
subject->nidentity++; subject->nidentity++;
if (!(subject->identities[subject->nidentity-1].type = strdup("saslUsername")) || if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "saslUsername") < 0 ||
!(subject->identities[subject->nidentity-1].name = strdup(saslUsername))) VIR_STRDUP(subject->identities[subject->nidentity-1].name, saslUsername) < 0)
goto no_memory; goto error;
} }
virObjectLock(vm); virObjectLock(vm);
@ -1041,6 +1041,7 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
if (localAddr) { if (localAddr) {
VIR_FREE(localAddr->service); VIR_FREE(localAddr->service);
VIR_FREE(localAddr->node); VIR_FREE(localAddr->node);
@ -1480,11 +1481,8 @@ qemuProcessExtractTTYPath(const char *haystack,
*/ */
while (*tmp) { while (*tmp) {
if (c_isspace(*tmp)) { if (c_isspace(*tmp)) {
*path = strndup(dev, tmp-dev); if (VIR_STRNDUP(*path, dev, tmp - dev) < 0)
if (*path == NULL) {
virReportOOMError();
return -1; return -1;
}
/* ... now further update offset till we get EOL */ /* ... now further update offset till we get EOL */
*offset = tmp - haystack; *offset = tmp - haystack;
@ -1539,12 +1537,8 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
} }
VIR_FREE(chr->source.data.file.path); VIR_FREE(chr->source.data.file.path);
chr->source.data.file.path = strdup(path); if (VIR_STRDUP(chr->source.data.file.path, path) < 0)
if (chr->source.data.file.path == NULL) {
virReportOOMError();
return -1; return -1;
}
} }
} }
@ -2666,12 +2660,12 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
if (state == VIR_DOMAIN_PAUSED && running) { if (state == VIR_DOMAIN_PAUSED && running) {
newState = VIR_DOMAIN_RUNNING; newState = VIR_DOMAIN_RUNNING;
newReason = VIR_DOMAIN_RUNNING_UNPAUSED; newReason = VIR_DOMAIN_RUNNING_UNPAUSED;
msg = strdup("was unpaused"); ignore_value(VIR_STRDUP_QUIET(msg, "was unpaused"));
} else if (state == VIR_DOMAIN_RUNNING && !running) { } else if (state == VIR_DOMAIN_RUNNING && !running) {
if (reason == VIR_DOMAIN_PAUSED_SHUTTING_DOWN) { if (reason == VIR_DOMAIN_PAUSED_SHUTTING_DOWN) {
newState = VIR_DOMAIN_SHUTDOWN; newState = VIR_DOMAIN_SHUTDOWN;
newReason = VIR_DOMAIN_SHUTDOWN_UNKNOWN; newReason = VIR_DOMAIN_SHUTDOWN_UNKNOWN;
msg = strdup("shutdown"); ignore_value(VIR_STRDUP_QUIET(msg, "shutdown"));
} else { } else {
newState = VIR_DOMAIN_PAUSED; newState = VIR_DOMAIN_PAUSED;
newReason = reason; newReason = reason;
@ -2681,19 +2675,14 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
} else if (state == VIR_DOMAIN_SHUTOFF && running) { } else if (state == VIR_DOMAIN_SHUTOFF && running) {
newState = VIR_DOMAIN_RUNNING; newState = VIR_DOMAIN_RUNNING;
newReason = VIR_DOMAIN_RUNNING_BOOTED; newReason = VIR_DOMAIN_RUNNING_BOOTED;
msg = strdup("finished booting"); ignore_value(VIR_STRDUP_QUIET(msg, "finished booting"));
} }
if (newState != VIR_DOMAIN_NOSTATE) { if (newState != VIR_DOMAIN_NOSTATE) {
if (!msg) {
virReportOOMError();
return -1;
}
VIR_DEBUG("Domain %s %s while its monitor was disconnected;" VIR_DEBUG("Domain %s %s while its monitor was disconnected;"
" changing state to %s (%s)", " changing state to %s (%s)",
vm->def->name, vm->def->name,
msg, NULLSTR(msg),
virDomainStateTypeToString(newState), virDomainStateTypeToString(newState),
virDomainStateReasonToString(newState, newReason)); virDomainStateReasonToString(newState, newReason));
VIR_FREE(msg); VIR_FREE(msg);
@ -3476,13 +3465,10 @@ int qemuProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) if (VIR_STRDUP(graphics->listens[0].address,
graphics->listens[0].address = strdup(cfg->vncListen); graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ?
else cfg->vncListen : cfg->spiceListen) < 0) {
graphics->listens[0].address = strdup(cfg->spiceListen);
if (!graphics->listens[0].address) {
VIR_SHRINK_N(graphics->listens, graphics->nListens, 1); VIR_SHRINK_N(graphics->listens, graphics->nListens, 1);
virReportOOMError();
goto cleanup; goto cleanup;
} }
} }
@ -4257,9 +4243,8 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
VIR_FREE(priv->pidfile); VIR_FREE(priv->pidfile);
if (pidfile && if (VIR_STRDUP(priv->pidfile, pidfile) < 0)
!(priv->pidfile = strdup(pidfile))) goto cleanup;
goto no_memory;
VIR_DEBUG("Detect security driver config"); VIR_DEBUG("Detect security driver config");
sec_managers = virSecurityManagerGetNested(driver->securityManager); sec_managers = virSecurityManagerGetNested(driver->securityManager);
@ -4280,11 +4265,11 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->def, vm->pid, seclabel) < 0) vm->def, vm->pid, seclabel) < 0)
goto cleanup; goto cleanup;
if (!(seclabeldef->model = strdup(model))) if (VIR_STRDUP(seclabeldef->model, model) < 0)
goto no_memory; goto cleanup;
if (!(seclabeldef->label = strdup(seclabel->label))) if (VIR_STRDUP(seclabeldef->label, seclabel->label) < 0)
goto no_memory; goto cleanup;
VIR_FREE(seclabel); VIR_FREE(seclabel);
} }