---
include/libvirt/libvirt.h.in | 10 +-
src/qemu/qemu_capabilities.c | 79 ++++----
src/qemu/qemu_cgroup.c | 4 +-
src/qemu/qemu_command.c | 419 +++++++++++++++++--------------------------
src/qemu/qemu_conf.c | 58 +++---
src/qemu/qemu_domain.c | 26 ++-
src/qemu/qemu_driver.c | 113 ++++--------
src/qemu/qemu_hotplug.c | 15 +-
src/qemu/qemu_migration.c | 20 +--
src/qemu/qemu_monitor_json.c | 63 ++-----
src/qemu/qemu_monitor_text.c | 15 +-
src/qemu/qemu_process.c | 64 +++----
src/remote/remote_driver.c | 2 +-
13 files changed, 333 insertions(+), 555 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 693b834..9a8090d 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1294,7 +1294,7 @@ typedef enum {
struct _virConnectCredential {
int type; /* One of virConnectCredentialType constants */
- const char *prompt; /* Prompt to show to user */
+ char *prompt; /* Prompt to show to user */
const char *challenge; /* Additional challenge to show */
const char *defresult; /* Optional default result */
char *result; /* Result to be filled with user response (or defresult) */
@@ -4504,8 +4504,8 @@ typedef enum {
*/
struct _virDomainEventGraphicsAddress {
int family; /* Address family, virDomainEventGraphicsAddressType */
- const char *node; /* Address of node (eg IP address, or UNIX path) */
- const char *service; /* Service name/number (eg TCP port, or NULL) */
+ char *node; /* Address of node (eg IP address, or UNIX path) */
+ char *service; /* Service name/number (eg TCP port, or NULL) */
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
@@ -4520,8 +4520,8 @@ typedef virDomainEventGraphicsAddress
*virDomainEventGraphicsAddressPtr;
* some examples are 'x509dname' and 'saslUsername'.
*/
struct _virDomainEventGraphicsSubjectIdentity {
- const char *type; /* Type of identity */
- const char *name; /* Identity value */
+ char *type; /* Type of identity */
+ char *name; /* Identity value */
};
typedef struct _virDomainEventGraphicsSubjectIdentity
virDomainEventGraphicsSubjectIdentity;
typedef virDomainEventGraphicsSubjectIdentity *virDomainEventGraphicsSubjectIdentityPtr;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a3a8d1f..7597a4b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -362,8 +362,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)
+ goto error;
p = t;
if ((t = strstr(p, "(default)")) && (!next || t < next))
@@ -374,9 +374,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;
+ goto error;
}
}
@@ -384,7 +384,8 @@ virQEMUCapsParseMachineTypesStr(const char *output,
VIR_REALLOC_N(qemuCaps->machineAliases, qemuCaps->nmachineTypes + 1)
< 0) {
VIR_FREE(name);
VIR_FREE(canonical);
- goto no_memory;
+ virReportOOMError();
+ goto error;
}
qemuCaps->nmachineTypes++;
if (canonical) {
@@ -402,8 +403,7 @@ virQEMUCapsParseMachineTypesStr(const char *output,
return 0;
-no_memory:
- virReportOOMError();
+error:
return -1;
}
@@ -499,10 +499,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;
@@ -552,10 +550,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;
@@ -1498,10 +1494,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;
@@ -1555,10 +1549,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;
@@ -1726,8 +1718,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)
@@ -1736,17 +1728,18 @@ 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 (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0)
+ goto error;
if (qemuCaps->machineAliases[i] &&
- !(ret->machineAliases[i] = strdup(qemuCaps->machineAliases[i])))
- goto no_memory;
+ VIR_STRDUP(ret->machineAliases[i], qemuCaps->machineAliases[i]) <
0)
+ goto error;
}
return ret;
no_memory:
virReportOOMError();
+error:
virObjectUnref(ret);
return NULL;
}
@@ -1848,11 +1841,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();
@@ -1897,12 +1889,12 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
if (VIR_ALLOC(mach) < 0)
goto no_memory;
if (qemuCaps->machineAliases[i]) {
- if (!(mach->name = strdup(qemuCaps->machineAliases[i])))
+ if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0)
goto no_memory;
- if (!(mach->canonical = strdup(qemuCaps->machineTypes[i])))
+ if (VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
goto no_memory;
} else {
- if (!(mach->name = strdup(qemuCaps->machineTypes[i])))
+ if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i]) < 0)
goto no_memory;
}
(*machines)[i] = mach;
@@ -2091,16 +2083,11 @@ 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 (machines[i]->alias &&
+ VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0)
+ goto cleanup;
+ if (VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0)
goto cleanup;
- }
if (machines[i]->isDefault)
defIdx = i;
}
@@ -2590,8 +2577,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. */
@@ -2621,8 +2608,6 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
return qemuCaps;
-no_memory:
- virReportOOMError();
error:
virObjectUnref(qemuCaps);
qemuCaps = NULL;
@@ -2672,10 +2657,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;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 4819cfe..57839b3 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -31,6 +31,7 @@
#include "viralloc.h"
#include "virerror.h"
#include "domain_audit.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -388,8 +389,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;
}
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 144620c..786ed1e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -322,10 +322,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
return -1;
} else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) {
- virReportOOMError();
+ if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0)
return -1;
- }
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"),
@@ -337,10 +335,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;
}
@@ -486,17 +482,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;
}
@@ -513,10 +502,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;
}
@@ -2418,13 +2404,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);
@@ -2442,6 +2426,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;
@@ -2455,9 +2440,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';
}
@@ -2482,11 +2466,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;
@@ -2513,9 +2495,8 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
VIR_FREE(options);
return 0;
-no_memory:
+error:
VIR_FREE(options);
- virReportOOMError();
return -1;
}
@@ -2555,9 +2536,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;
@@ -2567,9 +2547,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);
@@ -2580,9 +2559,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;
@@ -2593,9 +2571,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;
@@ -2675,7 +2652,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) {
@@ -2685,23 +2663,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;
}
@@ -2751,9 +2726,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;
@@ -5456,9 +5430,10 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
}
virBufferAddLit(&buf, "host");
} else {
- if (VIR_ALLOC(guest) < 0 ||
- (cpu->vendor_id && !(guest->vendor_id =
strdup(cpu->vendor_id))))
+ if (VIR_ALLOC(guest) < 0)
goto no_memory;
+ if (cpu->vendor_id && VIR_STRDUP(guest->vendor_id,
cpu->vendor_id) < 0)
+ goto cleanup;
guest->arch = host->arch;
if (cpu->match == VIR_CPU_MATCH_MINIMUM)
@@ -7039,8 +7014,8 @@ qemuBuildCommandLine(virConnectPtr conn,
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;
}
}
@@ -7875,8 +7850,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);
@@ -8312,17 +8287,16 @@ static int qemuStringToArgvEnv(const char *args,
next = strchr(curr, '\n');
if (next) {
- arg = strndup(curr, next-curr);
+ if (VIR_STRNDUP(arg, curr, next-curr) < 0)
+ goto error;
if (*next == '\'' ||
*next == '"')
next++;
} else {
- arg = strdup(curr);
+ if (VIR_STRDUP(arg, curr) < 0)
+ goto error;
}
- if (!arg)
- goto no_memory;
-
if (argalloc == argcount) {
if (VIR_REALLOC_N(arglist, argalloc+10) < 0) {
VIR_FREE(arg);
@@ -8372,13 +8346,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;
}
@@ -8452,14 +8427,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;
@@ -8563,11 +8538,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;
@@ -8592,11 +8564,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, ':');
@@ -8615,18 +8584,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);
@@ -8651,11 +8614,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") ||
@@ -8795,21 +8755,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
@@ -9161,14 +9119,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:")) {
@@ -9179,40 +9135,32 @@ 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 ((host2 && VIR_STRNDUP(source->data.udp.connectService,
+ svc1, host2 - svc1) < 0) ||
+ (!host2 && VIR_STRDUP(source->data.udp.connectService,
+ 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:") ||
@@ -9235,37 +9183,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 ((opt && VIR_STRNDUP(source->data.tcp.service, svc, opt - svc) <
0) ||
+ (!opt && VIR_STRDUP(source->data.tcp.service, 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 ((opt && VIR_STRNDUP(source->data.nix.path, val, opt - val) < 0)
||
+ (!opt && VIR_STRDUP(source->data.nix.path, 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);
@@ -9318,13 +9254,9 @@ 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 ((next && VIR_STRNDUP(model, p, next - p -1) < 0) ||
+ (!next && VIR_STRDUP(model, p) < 0))
+ goto error;
if (!STREQ(model, "qemu32") && !STREQ(model,
"qemu64")) {
if (!(cpu = qemuInitGuestCPU(dom)))
@@ -9347,13 +9279,9 @@ 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 ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) ||
+ (!next && VIR_STRDUP(feature, p) < 0))
+ goto error;
if (STREQ(feature, "kvmclock")) {
bool present = (policy == VIR_CPU_FEATURE_REQUIRE);
@@ -9411,13 +9339,9 @@ 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 ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) ||
+ (!next && VIR_STRDUP(feature, p) < 0))
+ goto error;
dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV);
@@ -9635,8 +9559,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;
@@ -9646,12 +9570,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;
@@ -9714,10 +9638,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 {
/*
@@ -9810,9 +9733,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")) {
@@ -9825,13 +9747,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;
@@ -9864,12 +9784,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:
@@ -9916,24 +9834,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();
@@ -9977,11 +9895,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);
@@ -9991,11 +9909,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 */
@@ -10004,11 +9922,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;
@@ -10077,17 +9992,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;
@@ -10189,9 +10104,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")) {
@@ -10224,8 +10138,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 */
@@ -10307,9 +10221,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++;
}
}
@@ -10338,9 +10251,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) {
@@ -10351,17 +10263,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;
@@ -10385,8 +10296,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) {
@@ -10398,14 +10309,14 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
sdl->data.sdl.fullscreen = fullscreen;
if (display &&
- !(sdl->data.sdl.display = strdup(display))) {
+ VIR_STRDUP(sdl->data.sdl.display, display) < 0) {
VIR_FREE(sdl);
- goto no_memory;
+ goto error;
}
if (xauth &&
- !(sdl->data.sdl.xauth = strdup(xauth))) {
+ 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) {
@@ -10522,7 +10433,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) {
@@ -10540,10 +10451,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 */
@@ -10558,7 +10467,7 @@ static int qemuParseProcFileStrings(int pid_value,
str[nstr-1] = NULL;
ret = nstr-1;
- *list = str;
+ *list = (const char **) str;
cleanup:
if (ret < 0) {
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index c16b90d..11ff61f 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -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;
@@ -240,8 +238,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;
@@ -347,8 +345,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);
@@ -379,16 +377,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;
}
@@ -486,8 +485,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;
}
@@ -586,10 +585,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);
}
@@ -1070,10 +1068,8 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr 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++;
}
@@ -1135,7 +1131,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
goto cleanup;
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) {
qemuSharedDiskEntryFree(new_entry, NULL);
virReportOOMError();
goto cleanup;
@@ -1148,7 +1144,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
} else {
if ((VIR_ALLOC(entry) < 0) ||
(VIR_ALLOC_N(entry->domains, 1) < 0) ||
- !(entry->domains[0] = strdup(name))) {
+ VIR_STRDUP(entry->domains[0], name) < 0) {
qemuSharedDiskEntryFree(entry, NULL);
virReportOOMError();
goto cleanup;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 33088ea..6dc0436 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -730,14 +730,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 */
@@ -761,8 +757,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 &&
@@ -804,8 +800,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;
}
@@ -814,10 +812,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
cleanup:
virObjectUnref(cfg);
return ret;
-
-no_memory:
- virReportOOMError();
- goto cleanup;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d5d7de3..feaf49a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1441,10 +1441,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;
}
@@ -2014,8 +2012,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)
@@ -3392,7 +3389,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);
@@ -5140,11 +5137,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);
@@ -5210,11 +5204,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);
@@ -6634,9 +6626,7 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom,
*nparams = 5;
}
- ret = strdup("posix");
- if (!ret)
- virReportOOMError();
+ ignore_value(VIR_STRDUP(ret, "posix"));
cleanup:
if (vm)
@@ -6694,11 +6684,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;
@@ -7062,13 +7049,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) {
@@ -7590,8 +7572,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) {
@@ -10582,9 +10564,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;
@@ -10873,9 +10854,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;
}
@@ -10952,12 +10932,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);
@@ -11561,13 +11538,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,
@@ -12346,14 +12319,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)
@@ -13260,10 +13229,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) {
@@ -13894,10 +13861,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++;
}
@@ -13954,15 +13919,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 (metadata && 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 (metadata && VIR_STRDUP(vm->def->title, metadata) < 0)
+ goto cleanup;
break;
case VIR_DOMAIN_METADATA_ELEMENT:
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
@@ -13982,15 +13945,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 (metadata && 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 (metadata && VIR_STRDUP(persistentDef->title, metadata) <
0)
+ goto cleanup;
break;
case VIR_DOMAIN_METADATA_ELEMENT:
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
@@ -14016,9 +13977,6 @@ cleanup:
virObjectUnref(caps);
virObjectUnref(cfg);
return ret;
-no_memory:
- virReportOOMError();
- goto cleanup;
}
static char *
@@ -14076,10 +14034,7 @@ qemuDomainGetMetadata(virDomainPtr dom,
goto cleanup;
}
- if (!(ret = strdup(field))) {
- virReportOOMError();
- goto cleanup;
- }
+ ignore_value(VIR_STRDUP(ret, field));
cleanup:
if (vm)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index a4f48b0..c464712 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1283,10 +1283,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;
@@ -1539,11 +1537,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"));
@@ -1568,11 +1563,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"));
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0732614..c69eea9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -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(NULL)))
@@ -460,15 +460,14 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
}
if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) {
- if (priv->lockState &&
- !(mig->lockState = strdup(priv->lockState)))
+ if (priv->lockState && 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;
}
@@ -2050,8 +2049,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
/* Target domain name, maybe renamed. */
if (dname) {
origname = def->name;
- def->name = strdup(dname);
- if (def->name == NULL)
+ if (VIR_STRDUP(def->name, dname) < 0)
goto cleanup;
}
@@ -2101,10 +2099,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;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 6fdd650..50596ea 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
@@ -4001,10 +3989,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) {
@@ -4019,10 +4005,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;
- }
}
}
@@ -4106,10 +4090,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;
@@ -4259,10 +4239,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
goto cleanup;
}
- if (!(eventlist[i] = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(eventlist[i], tmp) < 0)
goto cleanup;
- }
}
ret = n;
@@ -4384,10 +4362,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
goto cleanup;
}
- if (!(typelist[i] = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(typelist[i], tmp) < 0)
goto cleanup;
- }
}
ret = n;
@@ -4466,10 +4442,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
goto cleanup;
}
- if (!(proplist[i] = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(proplist[i], tmp) < 0)
goto cleanup;
- }
}
ret = n;
@@ -4520,10 +4494,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
goto cleanup;
}
- if (!(ret = strdup(arch))) {
- virReportOOMError();
- goto cleanup;
- }
+ ignore_value(VIR_STRDUP(ret, arch));
cleanup:
virJSONValueFree(cmd);
@@ -4817,10 +4788,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;
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 696961b..acc8a12 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -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,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3dd178c..2f2c92b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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(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(msg, "shutdown"));
} else {
newState = VIR_DOMAIN_PAUSED;
newReason = reason;
@@ -2681,7 +2675,7 @@ 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(msg, "finished booting"));
}
if (newState != VIR_DOMAIN_NOSTATE) {
@@ -3479,13 +3473,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;
}
}
@@ -4251,9 +4242,8 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
}
VIR_FREE(priv->pidfile);
- if (pidfile &&
- !(priv->pidfile = strdup(pidfile)))
- goto no_memory;
+ if (pidfile && VIR_STRDUP(priv->pidfile, pidfile) < 0)
+ goto cleanup;
VIR_DEBUG("Detect security driver config");
sec_managers = virSecurityManagerGetNested(driver->securityManager);
@@ -4274,11 +4264,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);
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 13212d0..97be2a0 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3733,7 +3733,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
}
if (interact[*ncred].challenge)
(*cred)[*ncred].challenge = interact[ninteract].challenge;
- (*cred)[*ncred].prompt = interact[ninteract].prompt;
+ (*cred)[*ncred].prompt = (char *) interact[ninteract].prompt;
if (interact[*ncred].defresult)
(*cred)[*ncred].defresult = interact[ninteract].defresult;
(*cred)[*ncred].result = NULL;
--
1.8.1.5