Adapt to VIR_STRDUP and VIR_STRNDUP in src/xen/*

This commit is contained in:
Michal Privoznik 2013-05-03 14:51:25 +02:00
parent ed2193b16b
commit 5162a07651
7 changed files with 57 additions and 127 deletions

View File

@ -292,14 +292,14 @@ xenLinuxDomainDeviceID(int domid, const char *path)
* /sys/devices/xen-backend/(vbd|tap)-{domid}-{devid}/statistics/{...}
*/
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/"))
mod_path = strdup(path);
else
ignore_value(virAsprintf(&mod_path, "/dev/%s", path));
if (!mod_path) {
virReportOOMError();
return -1;
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/")) {
if (VIR_STRDUP(mod_path, path) < 0)
return -1;
} else {
if (virAsprintf(&mod_path, "/dev/%s", path) < 0) {
virReportOOMError();
return -1;
}
}
retval = -1;

View File

@ -469,10 +469,8 @@ xenUnifiedConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int f
priv->opened[XEN_UNIFIED_INOTIFY_OFFSET] = 1;
#endif
if (!(priv->saveDir = strdup(XEN_SAVE_DIR))) {
virReportOOMError();
if (VIR_STRDUP(priv->saveDir, XEN_SAVE_DIR) < 0)
goto error;
}
if (virFileMakePath(priv->saveDir) < 0) {
VIR_ERROR(_("Errored to create save dir '%s': %s"), priv->saveDir,
@ -2586,8 +2584,8 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
if (VIR_ALLOC(info) < 0)
goto memory_error;
if (!(info->name = strdup(name)))
goto memory_error;
if (VIR_STRDUP(info->name, name) < 0)
goto error;
memcpy(info->uuid, uuid, VIR_UUID_BUFLEN);
info->id = id;
@ -2603,6 +2601,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
return 0;
memory_error:
virReportOOMError();
error:
if (info)
VIR_FREE(info->name);
VIR_FREE(info);

View File

@ -1142,16 +1142,12 @@ xenHypervisorGetSchedulerType(virConnectPtr conn,
switch (op.u.getschedulerid.sched_id){
case XEN_SCHEDULER_SEDF:
schedulertype = strdup("sedf");
if (schedulertype == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(schedulertype, "sedf"));
if (nparams)
*nparams = XEN_SCHED_SEDF_NPARAM;
break;
case XEN_SCHEDULER_CREDIT:
schedulertype = strdup("credit");
if (schedulertype == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(schedulertype, "credit"));
if (nparams)
*nparams = XEN_SCHED_CRED_NPARAM;
break;
@ -2541,14 +2537,9 @@ xenHypervisorDomainGetOSType(virConnectPtr conn,
return NULL;
}
if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM)
ostype = strdup("hvm");
else
ostype = strdup("linux");
if (ostype == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(ostype,
XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM ?
"hvm" : "linux"));
return ostype;
}

View File

@ -39,7 +39,7 @@
#include "virlog.h"
#include "viruuid.h"
#include "virfile.h"
#include "virstring.h"
#include "xm_internal.h" /* for xenXMDomainConfigParse */
#define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
@ -58,12 +58,9 @@ xenInotifyXenCacheLookup(virConnectPtr conn,
return -1;
}
*name = strdup(entry->def->name);
memcpy(uuid, entry->def->uuid, VIR_UUID_BUFLEN);
if (!*name) {
if (VIR_STRDUP(*name, entry->def->name) < 0) {
VIR_DEBUG("Error getting dom from def");
virReportOOMError();
return -1;
}
return 0;
@ -103,11 +100,8 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
list info */
for (i = 0; i < priv->configInfoList->count; i++) {
if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
*name = strdup(priv->configInfoList->doms[i]->name);
if (!*name) {
virReportOOMError();
if (VIR_STRDUP(*name, priv->configInfoList->doms[i]->name) < 0)
return -1;
}
memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN);
VIR_DEBUG("Found dom on list");
return 0;
@ -118,8 +112,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
return -1;
}
if (!(*name = strdup(def->name))) {
virReportOOMError();
if (VIR_STRDUP(*name, def->name) < 0) {
virDomainDefFree(def);
return -1;
}

View File

@ -772,8 +772,7 @@ xenDaemonListDomainsOld(virConnectPtr xend)
_for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
if (node->kind != SEXPR_VALUE)
continue;
ret[i] = strdup(node->u.value);
if (!ret[i])
if (VIR_STRDUP(ret[i], node->u.value) < 0)
goto no_memory;
i++;
}
@ -1396,14 +1395,8 @@ xenDaemonDomainGetOSType(virConnectPtr conn,
if (root == NULL)
return NULL;
if (sexpr_lookup(root, "domain/image/hvm")) {
type = strdup("hvm");
} else {
type = strdup("linux");
}
if (type == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(type,
sexpr_lookup(root, "domain/image/hvm") ? "hvm" : "linux"));
sexpr_free(root);
@ -2118,12 +2111,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
else
id = -1;
if (domname) {
name = strdup(domname);
if (name == NULL)
virReportOOMError();
}
ignore_value(VIR_STRDUP(name, domname));
sexpr_free(root);
}
@ -2284,12 +2272,9 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn,
priv->xendConfigVersion, 1) < 0)
goto cleanup;
if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (!(target = strdup(dev->data.disk->dst))) {
virReportOOMError();
goto cleanup;
}
}
if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
VIR_STRDUP(target, dev->data.disk->dst) < 0)
goto cleanup;
break;
case VIR_DOMAIN_DEVICE_NET:
@ -2303,10 +2288,8 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn,
char macStr[VIR_MAC_STRING_BUFLEN];
virMacAddrFormat(&dev->data.net->mac, macStr);
if (!(target = strdup(macStr))) {
virReportOOMError();
if (VIR_STRDUP(target, macStr) < 0)
goto cleanup;
}
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
@ -2618,12 +2601,9 @@ xenDaemonDomainSetAutostart(virConnectPtr conn,
/* Change the autostart value in place, then define the new sexpr */
VIR_FREE(autonode->u.s.car->u.value);
autonode->u.s.car->u.value = (autostart ? strdup("start")
: strdup("ignore"));
if (!(autonode->u.s.car->u.value)) {
virReportOOMError();
if (VIR_STRDUP(autonode->u.s.car->u.value,
autostart ? "start" : "ignore") < 0)
goto error;
}
if (sexpr2string(root, &buffer) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -2783,9 +2763,7 @@ xenDaemonDomainMigratePerform(virConnectPtr conn,
virURIFree(uriptr);
return -1;
}
hostname = strdup(uriptr->server);
if (!hostname) {
virReportOOMError();
if (VIR_STRDUP(hostname, uriptr->server) < 0) {
virURIFree(uriptr);
return -1;
}
@ -2805,19 +2783,13 @@ xenDaemonDomainMigratePerform(virConnectPtr conn,
/* Get the hostname. */
n = p - uri; /* n = Length of hostname in bytes. */
hostname = strdup(uri);
if (!hostname) {
virReportOOMError();
if (VIR_STRDUP(hostname, uri) < 0)
return -1;
}
hostname[n] = '\0';
}
else { /* "hostname" (or IP address) */
hostname = strdup(uri);
if (!hostname) {
virReportOOMError();
if (VIR_STRDUP(hostname, uri) < 0)
return -1;
}
}
VIR_DEBUG("hostname = %s, port = %s", hostname, port);
@ -2957,10 +2929,8 @@ xenDaemonListDefinedDomains(virConnectPtr conn,
if (node->kind != SEXPR_VALUE)
continue;
if ((names[ret++] = strdup(node->u.value)) == NULL) {
virReportOOMError();
if (VIR_STRDUP(names[ret++], node->u.value) < 0)
goto error;
}
if (ret >= maxnames)
break;
@ -3017,19 +2987,13 @@ xenDaemonGetSchedulerType(virConnectPtr conn,
goto error;
}
if (STREQ(ret, "credit")) {
schedulertype = strdup("credit");
if (schedulertype == NULL){
virReportOOMError();
if (VIR_STRDUP(schedulertype, "credit") < 0)
goto error;
}
if (nparams)
*nparams = XEN_SCHED_CRED_NPARAM;
} else if (STREQ(ret, "sedf")) {
schedulertype = strdup("sedf");
if (schedulertype == NULL){
virReportOOMError();
if (VIR_STRDUP(schedulertype, "sedf") < 0)
goto error;
}
if (nparams)
*nparams = XEN_SCHED_SEDF_NPARAM;
} else {

View File

@ -241,8 +241,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
virReportOOMError();
return -1;
}
if ((entry->filename = strdup(filename)) == NULL) {
virReportOOMError();
if (VIR_STRDUP(entry->filename, filename) < 0) {
VIR_FREE(entry);
return -1;
}
@ -1042,10 +1041,8 @@ xenXMDomainDefineXML(virConnectPtr conn, virDomainDefPtr def)
goto error;
}
if ((entry->filename = strdup(filename)) == NULL) {
virReportOOMError();
if (VIR_STRDUP(entry->filename, filename) < 0)
goto error;
}
entry->def = def;
if (virHashAddEntry(priv->configCache, filename, entry) < 0) {
@ -1134,7 +1131,7 @@ xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const void *name, void *data)
def = xenDaemonLookupByName(ctx->conn, name);
if (!def) {
if (!(ctx->names[ctx->count] = strdup(name)))
if (VIR_STRDUP(ctx->names[ctx->count], name) < 0)
ctx->oom = 1;
else
ctx->count++;
@ -1174,8 +1171,6 @@ xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
if (ctx.oom) {
for (i = 0; i < ctx.count; i++)
VIR_FREE(ctx.names[i]);
virReportOOMError();
goto cleanup;
}

View File

@ -50,6 +50,7 @@
#include "xen_driver.h"
#include "xs_internal.h"
#include "xen_hypervisor.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@ -428,11 +429,7 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac)
VIR_FREE(val);
if (match) {
ret = strdup(list[i]);
if (ret == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, list[i]));
break;
}
}
@ -481,10 +478,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
if ((devlen != len) || memcmp(val, dev, len)) {
VIR_FREE(val);
} else {
ret = strdup(list[i]);
if (ret == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, list[i]));
VIR_FREE(val);
VIR_FREE(list);
@ -504,10 +498,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
if ((devlen != len) || memcmp(val, dev, len)) {
VIR_FREE(val);
} else {
ret = strdup(list[i]);
if (ret == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, list[i]));
VIR_FREE(val);
VIR_FREE(list);
@ -559,7 +550,7 @@ xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
VIR_FREE(val);
if (match) {
ret = strdup(list[i]);
ignore_value(VIR_STRDUP(ret, list[i]));
break;
}
}
@ -665,22 +656,22 @@ xenStoreAddWatch(virConnectPtr conn,
}
}
if (VIR_ALLOC(watch) < 0)
goto no_memory;
watch->path = strdup(path);
watch->token = strdup(token);
watch->cb = cb;
watch->opaque = opaque;
if (watch->path == NULL || watch->token == NULL) {
goto no_memory;
if (VIR_ALLOC(watch) < 0) {
virReportOOMError();
goto error;
}
watch->cb = cb;
watch->opaque = opaque;
if (VIR_STRDUP(watch->path, path) < 0 ||
VIR_STRDUP(watch->token, token) < 0)
goto error;
/* Make space on list */
n = list->count;
if (VIR_REALLOC_N(list->watches, n + 1) < 0) {
goto no_memory;
virReportOOMError();
goto error;
}
list->watches[n] = watch;
@ -688,15 +679,12 @@ xenStoreAddWatch(virConnectPtr conn,
return xs_watch(priv->xshandle, watch->path, watch->token);
no_memory:
error:
if (watch) {
VIR_FREE(watch->path);
VIR_FREE(watch->token);
VIR_FREE(watch);
}
virReportOOMError();
return -1;
}