remoteDispatchFormatError (rerr, "%s", _("nparams too large"));
return -1;
}
- if (VIR_ALLOC_N(params, nparams)) {
+ if (VIR_ALLOC_N(params, nparams) < 0) {
remoteDispatchOOMError(rerr);
return -1;
}
ret->buffer.buffer_len = size;
if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
- char ebuf[1024];
virDomainFree (dom);
- remoteDispatchFormatError (rerr, "%s",
- virStrerror(errno, ebuf, sizeof ebuf));
+ remoteDispatchOOMError(rerr);
return -1;
}
ret->buffer.buffer_len = size;
if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
- char ebuf[1024];
virDomainFree (dom);
- remoteDispatchFormatError (rerr, "%s",
- virStrerror(errno, ebuf, sizeof ebuf));
+ remoteDispatchOOMError(rerr);
return -1;
}
goto error;
if (n) {
obj->nvcpupids = n;
- if (VIR_REALLOC_N(obj->vcpupids, obj->nvcpupids) < 0)
+ if (VIR_REALLOC_N(obj->vcpupids, obj->nvcpupids) < 0) {
+ virReportOOMError(conn);
goto error;
+ }
for (i = 0 ; i < n ; i++) {
char *pidstr = virXMLPropString(nodes[i], "pid");
/* Extract device name */
if (create == EXISTING_DEVICE) {
def->name = virXPathString(conn, "string(./name[1])", ctxt);
+
+ if (!def->name) {
+ virNodeDeviceReportError(conn, VIR_ERR_NO_NAME, NULL);
+ goto error;
+ }
} else {
def->name = strdup("new device");
- }
- if (!def->name) {
- virNodeDeviceReportError(conn, VIR_ERR_NO_NAME, NULL);
- goto error;
+ if (!def->name) {
+ virReportOOMError(conn);
+ goto error;
+ }
}
/* Extract device parent, if any */
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_VirtualMachinePowerState powerState;
int count = 0;
+ int i;
if (names == NULL || maxnames < 0) {
goto failure;
return count;
failure:
+ for (i = 0; i < count; ++i) {
+ VIR_FREE(names[i]);
+ }
+
count = -1;
goto cleanup;
ret = strdup(vm->def->os.type);
+ if (ret == NULL)
+ virReportOOMError(dom->conn);
+
cleanup:
if (vm)
virDomainObjUnlock(vm);
if (NULL == def->nets[i]->ifname) {
def->nets[i]->ifname = strdup(parentVeth);
}
- if (VIR_REALLOC_N(*veths, (*nveths)+1) < 0)
+ if (VIR_REALLOC_N(*veths, (*nveths)+1) < 0) {
+ virReportOOMError(conn);
goto error_exit;
- if (((*veths)[(*nveths)++] = strdup(containerVeth)) == NULL)
+ }
+ if (((*veths)[(*nveths)] = strdup(containerVeth)) == NULL) {
+ virReportOOMError(conn);
goto error_exit;
+ }
+ (*nveths)++;
if (NULL == def->nets[i]->ifname) {
- lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to allocate veth names"));
+ virReportOOMError(conn);
goto error_exit;
}
return 0;
}
-static char *lxcGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
- int *nparams)
+static char *lxcGetSchedulerType(virDomainPtr domain, int *nparams)
{
+ char *schedulerType = NULL;
+
if (nparams)
*nparams = 1;
- return strdup("posix");
+ schedulerType = strdup("posix");
+
+ if (schedulerType == NULL)
+ virReportOOMError(domain->conn);
+
+ return schedulerType;
}
static int lxcSetSchedulerParameters(virDomainPtr domain,
if (VIR_ALLOC(fs) < 0)
goto no_memory;
- if(virAsprintf(&veid_str, "%d", veid) < 0)
- goto error;
+ if (virAsprintf(&veid_str, "%d", veid) < 0)
+ goto no_memory;
fs->type = VIR_DOMAIN_FS_TYPE_MOUNT;
fs->src = openvz_replace(temp, "$VEID", veid_str);
int fd = -1, temp_fd = -1;
char line[PATH_MAX] ;
- if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0)
+ if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) {
+ virReportOOMError(NULL);
return -1;
+ }
fd = open(conf_file, O_RDONLY);
if (fd == -1)
if (confdir == NULL)
goto cleanup;
- if (virAsprintf(&default_conf_file, "%s/ve-%s.conf-sample", confdir, configfile_value) < 0)
+ if (virAsprintf(&default_conf_file, "%s/ve-%s.conf-sample", confdir, configfile_value) < 0) {
+ virReportOOMError(NULL);
goto cleanup;
+ }
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
goto cleanup;
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
- if (vmdef->os.init == NULL &&
- !(vmdef->os.init = strdup("/sbin/init"))) {
- goto cleanup;
+ if (vmdef->os.init == NULL) {
+ if (!(vmdef->os.init = strdup("/sbin/init"))) {
+ virReportOOMError(conn);
+ goto cleanup;
+ }
}
vm = virDomainFindByName(&driver->domains, vmdef->name);
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup;
- if (vmdef->os.init == NULL &&
- !(vmdef->os.init = strdup("/sbin/init")))
- goto cleanup;
+ if (vmdef->os.init == NULL) {
+ if (!(vmdef->os.init = strdup("/sbin/init"))) {
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
vm = virDomainFindByName(&driver->domains, vmdef->name);
if (vm) {
goto err;
}
}
- }
+ } else
+ virReportOOMError(conn);
close(fd);
return 0;
VIR_WARN("%s %d", "Unable to generate UUID for domain",
ids[i]);
}
- } else
+ } else {
+ virReportOOMError(conn);
goto err;
+ }
if (phypUUIDTable_WriteFile(conn) == -1)
goto err;
continue;
if (VIR_ALLOC(machine) < 0)
- goto error;
+ goto no_memory;
if (!(machine->name = strndup(p, t - p))) {
VIR_FREE(machine);
- goto error;
+ goto no_memory;
}
if (VIR_REALLOC_N(list, nitems + 1) < 0) {
VIR_FREE(machine->name);
VIR_FREE(machine);
- goto error;
+ goto no_memory;
}
p = t;
continue;
if (!(machine->canonical = strndup(p, t - p)))
- goto error;
+ goto no_memory;
}
} while ((p = next));
return 0;
-error:
+ no_memory:
+ virReportOOMError(NULL);
virCapabilitiesFreeMachines(list, nitems);
return -1;
}
return 0;
}
- if (VIR_ALLOC_N(list, info->nmachines) < 0)
+ if (VIR_ALLOC_N(list, info->nmachines) < 0) {
+ virReportOOMError(NULL);
return 0;
+ }
for (i = 0; i < info->nmachines; i++) {
if (VIR_ALLOC(list[i]) < 0) {
- virCapabilitiesFreeMachines(list, info->nmachines);
- return 0;
+ goto no_memory;
}
if (info->machines[i]->name &&
!(list[i]->name = strdup(info->machines[i]->name))) {
- virCapabilitiesFreeMachines(list, info->nmachines);
- return 0;
+ goto no_memory;
}
if (info->machines[i]->canonical &&
!(list[i]->canonical = strdup(info->machines[i]->canonical))) {
- virCapabilitiesFreeMachines(list, info->nmachines);
- return 0;
+ goto no_memory;
}
}
*nmachines = info->nmachines;
return 1;
+
+ no_memory:
+ virReportOOMError(NULL);
+ virCapabilitiesFreeMachines(list, info->nmachines);
+ return 0;
}
static int
if (info->machine) {
virCapsGuestMachinePtr machine;
- if (VIR_ALLOC(machine) < 0)
+ if (VIR_ALLOC(machine) < 0) {
+ virReportOOMError(NULL);
return -1;
+ }
if (!(machine->name = strdup(info->machine))) {
+ virReportOOMError(NULL);
VIR_FREE(machine);
return -1;
}
if (VIR_ALLOC_N(machines, nmachines) < 0) {
+ virReportOOMError(NULL);
VIR_FREE(machine->name);
VIR_FREE(machine);
return -1;
if (brname == NULL)
return -1;
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- brname = strdup(net->data.bridge.brname);
+ if (!(brname = strdup(net->data.bridge.brname))) {
+ virReportOOMError(conn);
+ return -1;
+ }
} else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"), net->type);
if (virAsprintf(&nic_name, "%s.%d",
net->model ? net->model : "nic",
- nic_index) < 0)
+ nic_index) < 0) {
+ virReportOOMError(NULL);
return -1;
+ }
if (virAsprintf(&hostnet_name, "%s.%d",
qemuNetTypeToHostNet(net->type),
hostnet_index) < 0) {
+ virReportOOMError(NULL);
VIR_FREE(nic_name);
return -1;
}
hostdev->source.subsys.u.pci.function);
if (ret < 0) {
pcidev = NULL;
- goto error;
+ goto no_memory;
}
ADD_ARG_LIT("-pcidevice");
ADD_ARG_LIT(pcidev);
for (i = 0 ; i < argcount ; i++)
VIR_FREE(arglist[i]);
VIR_FREE(arglist);
+ virReportOOMError(NULL);
return -1;
}
def->data.udp.connectHost = strndup(val, svc1-val);
else
def->data.udp.connectHost = strdup(val);
+
+ if (!def->data.udp.connectHost)
+ goto no_memory;
+
if (svc1) {
svc1++;
if (host2)
def->data.udp.connectService = strndup(svc1, host2-svc1);
else
def->data.udp.connectService = strdup(svc1);
+
+ if (!def->data.udp.connectService)
+ goto no_memory;
}
if (host2) {
def->data.udp.bindHost = strndup(host2, svc2-host2);
else
def->data.udp.bindHost = strdup(host2);
+
+ if (!def->data.udp.bindHost)
+ goto no_memory;
}
if (svc2) {
svc2++;
def->data.udp.bindService = strdup(svc2);
+ if (!def->data.udp.bindService)
+ goto no_memory;
}
} else if (STRPREFIX(val, "tcp:") ||
STRPREFIX(val, "telnet:")) {
def->data.tcp.listen = 1;
def->data.tcp.host = strndup(val, svc-val);
+ if (!def->data.tcp.host)
+ goto no_memory;
svc++;
if (opt) {
def->data.tcp.service = strndup(svc, opt-svc);
} else {
def->data.tcp.service = strdup(svc);
}
+ if (!def->data.tcp.service)
+ goto no_memory;
} else if (STRPREFIX(val, "unix:")) {
const char *opt;
val += strlen("unix:");
caps->host.secModel.model = strdup(model);
if (!caps->host.secModel.model) {
- char ebuf[1024];
- VIR_ERROR(_("Failed to copy secModel model: %s"),
- virStrerror(errno, ebuf, sizeof ebuf));
+ virReportOOMError(NULL);
return -1;
}
caps->host.secModel.doi = strdup(doi);
if (!caps->host.secModel.doi) {
- char ebuf[1024];
- VIR_ERROR(_("Failed to copy secModel DOI: %s"),
- virStrerror(errno, ebuf, sizeof ebuf));
+ virReportOOMError(NULL);
return -1;
}
int timeout = 3;
int ret;
- if (VIR_ALLOC(qemust) < 0)
+ if (VIR_ALLOC(qemust) < 0) {
+ virReportOOMError(st->conn);
return NULL;
+ }
qemust->fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (qemust->fd < 0)
size_t len;
int ret = -1;
- if (virAsprintf(&full, "%s\r", cmd) < 0)
+ if (virAsprintf(&full, "%s\r", cmd) < 0) {
+ virReportOOMError(NULL);
return -1;
+ }
len = strlen(full);
}
if(VIR_ALLOC(priv->callbackList)<0) {
- error(conn, VIR_ERR_INVALID_ARG, _("Error allocating callbacks list"));
+ virReportOOMError(conn);
goto failed;
}
if(VIR_ALLOC(priv->domainEvents)<0) {
- error(conn, VIR_ERR_INVALID_ARG, _("Error allocating domainEvents"));
+ virReportOOMError(conn);
goto failed;
}
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
/* Serialise the scheduler parameters. */
args.params.params_len = nparams;
if (VIR_ALLOC_N(args.params.params_val, nparams) < 0) {
- error (domain->conn, VIR_ERR_RPC, _("out of memory allocating array"));
+ virReportOOMError(domain->conn);
goto done;
}
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(pool->conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.names.names_len; ++i)
+ for (i = 0; i < ret.names.names_len; ++i) {
names[i] = strdup (ret.names.names_val[i]);
+ if (names[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(names[i]);
+
+ virReportOOMError(dev->conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.names.names_len;
cleanup:
* names and the list of pointers, so we have to strdup the
* names here.
*/
- for (i = 0; i < ret.uuids.uuids_len; ++i)
+ for (i = 0; i < ret.uuids.uuids_len; ++i) {
uuids[i] = strdup (ret.uuids.uuids_val[i]);
+ if (uuids[i] == NULL) {
+ for (--i; i >= 0; --i)
+ VIR_FREE(uuids[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ }
+
rv = ret.uuids.uuids_len;
cleanup:
struct private_data *priv = st->conn->privateData;
struct private_stream_data *stpriv;
- if (VIR_ALLOC(stpriv) < 0)
+ if (VIR_ALLOC(stpriv) < 0) {
+ virReportOOMError(st->conn);
return NULL;
+ }
/* Initialize call object used to receive replies */
stpriv->proc_nr = proc_nr;
struct remote_message_header hdr;
struct remote_thread_call *rv;
- if (VIR_ALLOC(rv) < 0)
+ if (VIR_ALLOC(rv) < 0) {
+ virReportOOMError(conn);
return NULL;
+ }
if (virCondInit(&rv->cond) < 0) {
VIR_FREE(rv);
if (secretLoadValidateUUID(conn, def, xml_basename) < 0)
goto cleanup;
- if (VIR_ALLOC(secret) < 0)
+ if (VIR_ALLOC(secret) < 0) {
+ virReportOOMError(conn);
goto cleanup;
+ }
secret->def = def;
def = NULL;
char *uuidstr;
if (i == maxuuids)
break;
- if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0)
+ if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) {
+ virReportOOMError(conn);
goto cleanup;
+ }
virUUIDFormat(secret->def->uuid, uuidstr);
uuids[i] = uuidstr;
i++;
int rc = -1;
/* create string that is '<str> \0' for accurate matching */
- if (virAsprintf(&tmp, "%s ", str) == -1)
+ if (virAsprintf(&tmp, "%s ", str) == -1) {
+ virReportOOMError(NULL);
return rc;
+ }
if (check_enforcing != 0) {
/* create string that is '<str> (enforce)\0' for accurate matching */
if (virAsprintf(&etmp, "%s (enforce)", str) == -1) {
VIR_FREE(tmp);
+ virReportOOMError(NULL);
return rc;
}
}
}
*block_device = strdup(block_dirent->d_name);
+
+ if (*block_device == NULL) {
+ virReportOOMError(conn);
+ closedir(block_dir);
+ retval = -1;
+ goto out;
+ }
+
VIR_DEBUG(_("Block device is '%s'"), *block_device);
break;
blockp++;
*block_device = strdup(blockp);
+ if (*block_device == NULL) {
+ virReportOOMError(conn);
+ retval = -1;
+ goto out;
+ }
+
VIR_DEBUG(_("Block device is '%s'"), *block_device);
}
+out:
return retval;
}
return(NULL);
}
ret = strndup(base, ctxt->cur - base);
+ if (ret == NULL) {
+ virReportOOMError(NULL);
+ return NULL;
+ }
NEXT;
} else if ((ctxt->cur + 6 < ctxt->end) && (ctxt->cur[0] == '"') &&
(ctxt->cur[1] == '"') && (ctxt->cur[2] == '"')) {
return(NULL);
}
ret = strndup(base, ctxt->cur - base);
+ if (ret == NULL) {
+ virReportOOMError(NULL);
+ return NULL;
+ }
ctxt->cur += 3;
} else if (CUR == '"') {
NEXT;
return(NULL);
}
ret = strndup(base, ctxt->cur - base);
+ if (ret == NULL) {
+ virReportOOMError(NULL);
+ return NULL;
+ }
NEXT;
}
return(ret);
if (!cur) {
if (VIR_ALLOC(cur) < 0) {
+ virReportOOMError(NULL);
virConfFreeValue(value);
return (-1);
}
cur->comment = NULL;
if (!(cur->name = strdup(setting))) {
+ virReportOOMError(NULL);
virConfFreeValue(value);
VIR_FREE(cur);
return (-1);
return ret;
}
-static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
+static char *vboxDomainGetOSType(virDomainPtr dom) {
/* Returning "hvm" always as suggested on list, cause
* this functions seems to be badly named and it
* is supposed to pass the ABI name and not the domain
* operating system driver as I had imagined ;)
*/
- return strdup("hvm");
+ char *osType = strdup("hvm");
+
+ if (osType == NULL)
+ virReportOOMError(dom->conn);
+
+ return osType;
}
static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory) {
if (valueDisplayUtf8)
sdlDisplay = strdup(valueDisplayUtf8);
if (sdlDisplay == NULL) {
- vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+ virReportOOMError(dom->conn);
/* just don't go to cleanup yet as it is ok to have
* sdlDisplay as NULL and we check it below if it
* exist and then only use it there
if (valueDisplayUtf8)
guiDisplay = strdup(valueDisplayUtf8);
if (guiDisplay == NULL) {
- vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+ virReportOOMError(dom->conn);
/* just don't go to cleanup yet as it is ok to have
* guiDisplay as NULL and we check it below if it
* exist and then only use it there
def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
def->graphics[def->ngraphics]->data.desktop.display = strdup(getenv("DISPLAY"));
if (def->graphics[def->ngraphics]->data.desktop.display == NULL) {
- vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+ virReportOOMError(dom->conn);
/* just don't go to cleanup yet as it is ok to have
* display as NULL
*/
def->os.type = strdup("hvm");
+ if (def->os.type == NULL) {
+ virReportOOMError(dom->conn);
+ goto cleanup;
+ }
+
dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml,
VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) {
def->os.type = strdup("hvm");
+ if (def->os.type == NULL) {
+ virReportOOMError(dom->conn);
+ goto cleanup;
+ }
+
dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml,
VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) {
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return(NULL);
- if (VIR_ALLOC_N(cpulist, priv->nbNodeCpus) < 0)
+ if (VIR_ALLOC_N(cpulist, priv->nbNodeCpus) < 0) {
+ virReportOOMError(dom->conn);
goto done;
- if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0)
+ }
+ if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) {
+ virReportOOMError(dom->conn);
goto done;
+ }
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
if (xalloc_oversized(nb_vcpu, cpumaplen) ||
- VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0)
+ VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0) {
+ virReportOOMError(dom->conn);
goto done;
+ }
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
cpumap, cpumaplen)) >= 0) {
switch (op.u.getschedulerid.sched_id){
case XEN_SCHEDULER_SEDF:
schedulertype = strdup("sedf");
+ if (schedulertype == NULL)
+ virReportOOMError(domain->conn);
if (nparams)
*nparams = 6;
break;
case XEN_SCHEDULER_CREDIT:
schedulertype = strdup("credit");
+ if (schedulertype == NULL)
+ virReportOOMError(domain->conn);
if (nparams)
*nparams = 2;
break;
{
xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo;
+ char *ostype = NULL;
priv = (xenUnifiedPrivatePtr) dom->conn->privateData;
if (priv->handle < 0)
return (NULL);
if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM)
- return strdup("hvm");
- return strdup("linux");
+ ostype = strdup("hvm");
+ else
+ ostype = strdup("linux");
+
+ if (ostype == NULL)
+ virReportOOMError(dom->conn);
+
+ return ostype;
}
virDomainPtr
if (!*name) {
DEBUG0("Error getting dom from def");
+ virReportOOMError(conn);
return -1;
}
return 0;
if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
*name = strdup(priv->configInfoList->doms[i]->name);
if (!*name) {
- virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
- _("finding dom for %s"), uuid_str);
+ virReportOOMError(conn);
return -1;
}
memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN);
return -1;
}
- if (!(*name = strdup(dom->name)))
+ if (!(*name = strdup(dom->name))) {
+ virReportOOMError(conn);
return -1;
+ }
memcpy(uuid, dom->uuid, VIR_UUID_BUFLEN);
virDomainFree(dom);
/* succeeded too find domain by uuid */
* Returns 0 or -1 in case of error.
*/
virDrvOpenStatus
-xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
+xenInotifyOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
{
priv->useXenConfigCache = 0;
if (VIR_ALLOC(priv->configInfoList) < 0) {
- virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to allocate configInfoList"));
+ virReportOOMError(conn);
return -1;
}
"%s", _("domain information incomplete, missing name"));
goto error;
}
- if (domname)
+ if (domname) {
*domname = strdup(name);
+ if (*domname == NULL) {
+ virReportOOMError(xend);
+ goto error;
+ }
+ }
if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
goto failed;
} else if (STRCASEEQ (conn->uri->scheme, "http")) {
if (conn->uri->port &&
- virAsprintf(&port, "%d", conn->uri->port) == -1)
+ virAsprintf(&port, "%d", conn->uri->port) == -1) {
+ virReportOOMError(conn);
goto failed;
+ }
if (xenDaemonOpen_tcp(conn,
conn->uri->server ? conn->uri->server : "localhost",
type = strdup("linux");
}
+ if (type == NULL)
+ virReportOOMError(domain->conn);
+
sexpr_free(root);
return(type);
if (id >= 0) {
if (!memcmp(uuid, ident, VIR_UUID_BUFLEN)) {
name = strdup(*tmp);
+
+ if (name == NULL)
+ virReportOOMError(conn);
+
break;
}
}
id = sexpr_int(root, "domain/domid");
else
id = -1;
- name = domname ? strdup(domname) : NULL;
+
+ if (domname) {
+ name = strdup(domname);
+
+ if (name == NULL)
+ virReportOOMError(conn);
+ }
+
sexpr_free(root);
}
autonode->u.s.car->u.value = (autostart ? strdup("start")
: strdup("ignore"));
if (!(autonode->u.s.car->u.value)) {
- virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("no memory"));
+ virReportOOMError(domain->conn);
goto error;
}
static int
xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
struct sexpr *root = NULL;
- int ret = -1;
+ int i, ret = -1;
struct sexpr *_for_i, *node;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
if (node->kind != SEXPR_VALUE)
continue;
- names[ret++] = strdup(node->u.value);
+ if ((names[ret++] = strdup(node->u.value)) == NULL) {
+ virReportOOMError(conn);
+ goto error;
+ }
+
if (ret >= maxnames)
break;
}
error:
+ for (i = 0; i < ret; ++i)
+ VIR_FREE(names[i]);
+
sexpr_free(root);
return(ret);
}
if (STREQ (ret, "credit")) {
schedulertype = strdup("credit");
if (schedulertype == NULL){
- virXendError(domain->conn, VIR_ERR_SYSTEM_ERROR, "%s", _("strdup failed"));
+ virReportOOMError(domain->conn);
goto error;
}
*nparams = XEN_SCHED_CRED_NPARAM;
} else if (STREQ (ret, "sedf")) {
schedulertype = strdup("sedf");
if (schedulertype == NULL){
- virXendError(domain->conn, VIR_ERR_SYSTEM_ERROR, "%s", _("strdup failed"));
+ virReportOOMError(domain->conn);
goto error;
}
*nparams = XEN_SCHED_SEDF_NPARAM;
int i;
const char *defaultArch, *defaultMachine;
- if (VIR_ALLOC(def) < 0)
+ if (VIR_ALLOC(def) < 0) {
+ virReportOOMError(conn);
return NULL;
+ }
def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1;
}
if (VIR_ALLOC(net) < 0)
- goto cleanup;
+ goto no_memory;
if (mac[0]) {
unsigned int rawmac[6];
goto skippci;
if (VIR_ALLOC(hostdev) < 0)
- goto cleanup;
+ goto no_memory;
hostdev->managed = 0;
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL;
- if (VIR_ALLOC(value) < 0)
+ if (VIR_ALLOC(value) < 0) {
+ virReportOOMError(NULL);
return -1;
+ }
value->type = VIR_CONF_LONG;
value->next = NULL;
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL;
- if (VIR_ALLOC(value) < 0)
+ if (VIR_ALLOC(value) < 0) {
+ virReportOOMError(NULL);
return -1;
+ }
value->type = VIR_CONF_STRING;
value->next = NULL;
if (!(value->str = strdup(str))) {
VIR_FREE(value);
+ virReportOOMError(NULL);
return -1;
}
if (!hasPCI)
return 0;
- if (VIR_ALLOC(pciVal) < 0)
+ if (VIR_ALLOC(pciVal) < 0) {
+ virReportOOMError(conn);
return -1;
+ }
pciVal->type = VIR_CONF_LIST;
pciVal->list = NULL;
def->hostdevs[i]->source.subsys.u.pci.domain,
def->hostdevs[i]->source.subsys.u.pci.bus,
def->hostdevs[i]->source.subsys.u.pci.slot,
- def->hostdevs[i]->source.subsys.u.pci.function) < 0)
+ def->hostdevs[i]->source.subsys.u.pci.function) < 0) {
+ virReportOOMError(conn);
goto error;
+ }
if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf);
struct xenXMListIteratorContext {
virConnectPtr conn;
+ int oom;
int max;
int count;
char ** names;
struct xenXMListIteratorContext *ctx = data;
virDomainPtr dom = NULL;
+ if (ctx->oom)
+ return;
+
if (ctx->count == ctx->max)
return;
dom = xenDaemonLookupByName(ctx->conn, name);
if (!dom) {
- ctx->names[ctx->count] = strdup(name);
- ctx->count++;
+ if (!(ctx->names[ctx->count] = strdup(name)))
+ ctx->oom = 1;
+ else
+ ctx->count++;
} else {
virDomainFree(dom);
}
int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
xenUnifiedPrivatePtr priv;
struct xenXMListIteratorContext ctx;
- int ret = -1;
+ int i, ret = -1;
if (!VIR_IS_CONNECT(conn)) {
xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
maxnames = virHashSize(priv->configCache);
ctx.conn = conn;
+ ctx.oom = 0;
ctx.count = 0;
ctx.max = maxnames;
ctx.names = names;
virHashForEach(priv->nameConfigMap, xenXMListIterator, &ctx);
+
+ if (ctx.oom) {
+ for (i = 0; i < ctx.count; i++)
+ VIR_FREE(ctx.names[i]);
+
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+
ret = ctx.count;
cleanup:
#ifndef PROXY
/* Init activeDomainList */
if (VIR_ALLOC(priv->activeDomainList) < 0) {
- virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to allocate activeDomainList"));
+ virReportOOMError(conn);
return -1;
}
/* Init watch list before filling in domInfoList,
so we can know if it is the first time through
when the callback fires */
- if ( VIR_ALLOC(priv->xsWatchList) < 0 ) {
- virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to allocate xsWatchList"));
+ if (VIR_ALLOC(priv->xsWatchList) < 0) {
+ virReportOOMError(conn);
return -1;
}
}
if (str == NULL)
str = strdup("linux");
-
+ if (str == NULL)
+ virReportOOMError(conn);
return (str);
}
if (match) {
ret = strdup(list[i]);
+
+ if (ret == NULL)
+ virReportOOMError(conn);
+
break;
}
}
if (val == NULL)
break;
if ((devlen != len) || memcmp(val, dev, len)) {
- free (val);
+ VIR_FREE (val);
} else {
ret = strdup(list[i]);
- free (val);
- free (list);
+
+ if (ret == NULL)
+ virReportOOMError(conn);
+
+ VIR_FREE (val);
+ VIR_FREE (list);
return (ret);
}
}
- free (list);
+ VIR_FREE (list);
}
snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id);
list = xs_directory(priv->xshandle, 0, dir, &num);
if (val == NULL)
break;
if ((devlen != len) || memcmp(val, dev, len)) {
- free (val);
+ VIR_FREE (val);
} else {
ret = strdup(list[i]);
- free (val);
- free (list);
+
+ if (ret == NULL)
+ virReportOOMError(conn);
+
+ VIR_FREE (val);
+ VIR_FREE (list);
return (ret);
}
}
- free (list);
+ VIR_FREE (list);
}
return (NULL);
}
xenStoreWatchCallback cb,
void *opaque)
{
- xenStoreWatchPtr watch;
+ xenStoreWatchPtr watch = NULL;
int n;
xenStoreWatchListPtr list;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
}
if (VIR_ALLOC(watch) < 0)
- return -1;
+ 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;
+ }
+
/* Make space on list */
n = list->count;
if (VIR_REALLOC_N(list->watches, n + 1) < 0) {
- virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR,
- "%s", _("reallocating list"));
- VIR_FREE(watch);
- return -1;
+ goto no_memory;
}
list->watches[n] = watch;
list->count++;
return xs_watch(priv->xshandle, watch->path, watch->token);
+
+ no_memory:
+ if (watch) {
+ VIR_FREE(watch->path);
+ VIR_FREE(watch->token);
+ VIR_FREE(watch);
+ }
+
+ virReportOOMError(conn);
+
+ return -1;
}
/*