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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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