1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Add missing OOM error checks, reports and cleanups

This commit is contained in:
Matthias Bolte 2009-11-08 22:08:54 +01:00
parent 457a10d91d
commit 790f0b3057
23 changed files with 444 additions and 129 deletions

View File

@ -565,7 +565,7 @@ remoteDispatchDomainSetSchedulerParameters (struct qemud_server *server ATTRIBUT
remoteDispatchFormatError (rerr, "%s", _("nparams too large")); remoteDispatchFormatError (rerr, "%s", _("nparams too large"));
return -1; return -1;
} }
if (VIR_ALLOC_N(params, nparams)) { if (VIR_ALLOC_N(params, nparams) < 0) {
remoteDispatchOOMError(rerr); remoteDispatchOOMError(rerr);
return -1; return -1;
} }
@ -721,10 +721,8 @@ remoteDispatchDomainBlockPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
ret->buffer.buffer_len = size; ret->buffer.buffer_len = size;
if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) { if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
char ebuf[1024];
virDomainFree (dom); virDomainFree (dom);
remoteDispatchFormatError (rerr, "%s", remoteDispatchOOMError(rerr);
virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }
@ -772,10 +770,8 @@ remoteDispatchDomainMemoryPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
ret->buffer.buffer_len = size; ret->buffer.buffer_len = size;
if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) { if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
char ebuf[1024];
virDomainFree (dom); virDomainFree (dom);
remoteDispatchFormatError (rerr, "%s", remoteDispatchOOMError(rerr);
virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }

View File

@ -3431,8 +3431,10 @@ static virDomainObjPtr virDomainObjParseXML(virConnectPtr conn,
goto error; goto error;
if (n) { if (n) {
obj->nvcpupids = 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; goto error;
}
for (i = 0 ; i < n ; i++) { for (i = 0 ; i < n ; i++) {
char *pidstr = virXMLPropString(nodes[i], "pid"); char *pidstr = virXMLPropString(nodes[i], "pid");

View File

@ -1057,13 +1057,18 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create
/* Extract device name */ /* Extract device name */
if (create == EXISTING_DEVICE) { if (create == EXISTING_DEVICE) {
def->name = virXPathString(conn, "string(./name[1])", ctxt); def->name = virXPathString(conn, "string(./name[1])", ctxt);
if (!def->name) {
virNodeDeviceReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error;
}
} else { } else {
def->name = strdup("new device"); def->name = strdup("new device");
}
if (!def->name) { if (!def->name) {
virNodeDeviceReportError(conn, VIR_ERR_NO_NAME, NULL); virReportOOMError(conn);
goto error; goto error;
}
} }
/* Extract device parent, if any */ /* Extract device parent, if any */

View File

@ -2262,6 +2262,7 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_VirtualMachinePowerState powerState; esxVI_VirtualMachinePowerState powerState;
int count = 0; int count = 0;
int i;
if (names == NULL || maxnames < 0) { if (names == NULL || maxnames < 0) {
goto failure; goto failure;
@ -2329,6 +2330,10 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
return count; return count;
failure: failure:
for (i = 0; i < count; ++i) {
VIR_FREE(names[i]);
}
count = -1; count = -1;
goto cleanup; goto cleanup;

View File

@ -445,6 +445,9 @@ static char *lxcGetOSType(virDomainPtr dom)
ret = strdup(vm->def->os.type); ret = strdup(vm->def->os.type);
if (ret == NULL)
virReportOOMError(dom->conn);
cleanup: cleanup:
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
@ -724,14 +727,18 @@ static int lxcSetupInterfaces(virConnectPtr conn,
if (NULL == def->nets[i]->ifname) { if (NULL == def->nets[i]->ifname) {
def->nets[i]->ifname = strdup(parentVeth); 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; goto error_exit;
if (((*veths)[(*nveths)++] = strdup(containerVeth)) == NULL) }
if (((*veths)[(*nveths)] = strdup(containerVeth)) == NULL) {
virReportOOMError(conn);
goto error_exit; goto error_exit;
}
(*nveths)++;
if (NULL == def->nets[i]->ifname) { if (NULL == def->nets[i]->ifname) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, virReportOOMError(conn);
"%s", _("Failed to allocate veth names"));
goto error_exit; goto error_exit;
} }
@ -1771,13 +1778,19 @@ static int lxcVersion(virConnectPtr conn, unsigned long *version)
return 0; return 0;
} }
static char *lxcGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, static char *lxcGetSchedulerType(virDomainPtr domain, int *nparams)
int *nparams)
{ {
char *schedulerType = NULL;
if (nparams) if (nparams)
*nparams = 1; *nparams = 1;
return strdup("posix"); schedulerType = strdup("posix");
if (schedulerType == NULL)
virReportOOMError(domain->conn);
return schedulerType;
} }
static int lxcSetSchedulerParameters(virDomainPtr domain, static int lxcSetSchedulerParameters(virDomainPtr domain,

View File

@ -386,8 +386,8 @@ openvzReadFSConf(virConnectPtr conn,
if (VIR_ALLOC(fs) < 0) if (VIR_ALLOC(fs) < 0)
goto no_memory; goto no_memory;
if(virAsprintf(&veid_str, "%d", veid) < 0) if (virAsprintf(&veid_str, "%d", veid) < 0)
goto error; goto no_memory;
fs->type = VIR_DOMAIN_FS_TYPE_MOUNT; fs->type = VIR_DOMAIN_FS_TYPE_MOUNT;
fs->src = openvz_replace(temp, "$VEID", veid_str); fs->src = openvz_replace(temp, "$VEID", veid_str);
@ -547,8 +547,10 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va
int fd = -1, temp_fd = -1; int fd = -1, temp_fd = -1;
char line[PATH_MAX] ; 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; return -1;
}
fd = open(conf_file, O_RDONLY); fd = open(conf_file, O_RDONLY);
if (fd == -1) if (fd == -1)
@ -733,8 +735,10 @@ openvzCopyDefaultConfig(int vpsid)
if (confdir == NULL) if (confdir == NULL)
goto cleanup; 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; goto cleanup;
}
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0) if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
goto cleanup; goto cleanup;

View File

@ -767,9 +767,11 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
VIR_DOMAIN_XML_INACTIVE)) == NULL) VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup; goto cleanup;
if (vmdef->os.init == NULL && if (vmdef->os.init == NULL) {
!(vmdef->os.init = strdup("/sbin/init"))) { if (!(vmdef->os.init = strdup("/sbin/init"))) {
goto cleanup; virReportOOMError(conn);
goto cleanup;
}
} }
vm = virDomainFindByName(&driver->domains, vmdef->name); vm = virDomainFindByName(&driver->domains, vmdef->name);
@ -844,9 +846,12 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
VIR_DOMAIN_XML_INACTIVE)) == NULL) VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup; goto cleanup;
if (vmdef->os.init == NULL && if (vmdef->os.init == NULL) {
!(vmdef->os.init = strdup("/sbin/init"))) if (!(vmdef->os.init = strdup("/sbin/init"))) {
goto cleanup; virReportOOMError(conn);
goto cleanup;
}
}
vm = virDomainFindByName(&driver->domains, vmdef->name); vm = virDomainFindByName(&driver->domains, vmdef->name);
if (vm) { if (vm) {

View File

@ -1732,7 +1732,8 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
goto err; goto err;
} }
} }
} } else
virReportOOMError(conn);
close(fd); close(fd);
return 0; return 0;
@ -1833,8 +1834,10 @@ phypUUIDTable_Init(virConnectPtr conn)
VIR_WARN("%s %d", "Unable to generate UUID for domain", VIR_WARN("%s %d", "Unable to generate UUID for domain",
ids[i]); ids[i]);
} }
} else } else {
virReportOOMError(conn);
goto err; goto err;
}
if (phypUUIDTable_WriteFile(conn) == -1) if (phypUUIDTable_WriteFile(conn) == -1)
goto err; goto err;

View File

@ -417,17 +417,17 @@ qemudParseMachineTypesStr(const char *output,
continue; continue;
if (VIR_ALLOC(machine) < 0) if (VIR_ALLOC(machine) < 0)
goto error; goto no_memory;
if (!(machine->name = strndup(p, t - p))) { if (!(machine->name = strndup(p, t - p))) {
VIR_FREE(machine); VIR_FREE(machine);
goto error; goto no_memory;
} }
if (VIR_REALLOC_N(list, nitems + 1) < 0) { if (VIR_REALLOC_N(list, nitems + 1) < 0) {
VIR_FREE(machine->name); VIR_FREE(machine->name);
VIR_FREE(machine); VIR_FREE(machine);
goto error; goto no_memory;
} }
p = t; p = t;
@ -446,7 +446,7 @@ qemudParseMachineTypesStr(const char *output,
continue; continue;
if (!(machine->canonical = strndup(p, t - p))) if (!(machine->canonical = strndup(p, t - p)))
goto error; goto no_memory;
} }
} while ((p = next)); } while ((p = next));
@ -455,7 +455,8 @@ qemudParseMachineTypesStr(const char *output,
return 0; return 0;
error: no_memory:
virReportOOMError(NULL);
virCapabilitiesFreeMachines(list, nitems); virCapabilitiesFreeMachines(list, nitems);
return -1; return -1;
} }
@ -537,23 +538,22 @@ qemudGetOldMachinesFromInfo(virCapsGuestDomainInfoPtr info,
return 0; return 0;
} }
if (VIR_ALLOC_N(list, info->nmachines) < 0) if (VIR_ALLOC_N(list, info->nmachines) < 0) {
virReportOOMError(NULL);
return 0; return 0;
}
for (i = 0; i < info->nmachines; i++) { for (i = 0; i < info->nmachines; i++) {
if (VIR_ALLOC(list[i]) < 0) { if (VIR_ALLOC(list[i]) < 0) {
virCapabilitiesFreeMachines(list, info->nmachines); goto no_memory;
return 0;
} }
if (info->machines[i]->name && if (info->machines[i]->name &&
!(list[i]->name = strdup(info->machines[i]->name))) { !(list[i]->name = strdup(info->machines[i]->name))) {
virCapabilitiesFreeMachines(list, info->nmachines); goto no_memory;
return 0;
} }
if (info->machines[i]->canonical && if (info->machines[i]->canonical &&
!(list[i]->canonical = strdup(info->machines[i]->canonical))) { !(list[i]->canonical = strdup(info->machines[i]->canonical))) {
virCapabilitiesFreeMachines(list, info->nmachines); goto no_memory;
return 0;
} }
} }
@ -561,6 +561,11 @@ qemudGetOldMachinesFromInfo(virCapsGuestDomainInfoPtr info,
*nmachines = info->nmachines; *nmachines = info->nmachines;
return 1; return 1;
no_memory:
virReportOOMError(NULL);
virCapabilitiesFreeMachines(list, info->nmachines);
return 0;
} }
static int static int
@ -668,15 +673,19 @@ qemudCapsInitGuest(virCapsPtr caps,
if (info->machine) { if (info->machine) {
virCapsGuestMachinePtr machine; virCapsGuestMachinePtr machine;
if (VIR_ALLOC(machine) < 0) if (VIR_ALLOC(machine) < 0) {
virReportOOMError(NULL);
return -1; return -1;
}
if (!(machine->name = strdup(info->machine))) { if (!(machine->name = strdup(info->machine))) {
virReportOOMError(NULL);
VIR_FREE(machine); VIR_FREE(machine);
return -1; return -1;
} }
if (VIR_ALLOC_N(machines, nmachines) < 0) { if (VIR_ALLOC_N(machines, nmachines) < 0) {
virReportOOMError(NULL);
VIR_FREE(machine->name); VIR_FREE(machine->name);
VIR_FREE(machine); VIR_FREE(machine);
return -1; return -1;
@ -1166,7 +1175,10 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
if (brname == NULL) if (brname == NULL)
return -1; return -1;
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { } 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 { } else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"), net->type); _("Network type %d is not supported"), net->type);
@ -1276,12 +1288,15 @@ qemuAssignNetNames(virDomainDefPtr def,
if (virAsprintf(&nic_name, "%s.%d", if (virAsprintf(&nic_name, "%s.%d",
net->model ? net->model : "nic", net->model ? net->model : "nic",
nic_index) < 0) nic_index) < 0) {
virReportOOMError(NULL);
return -1; return -1;
}
if (virAsprintf(&hostnet_name, "%s.%d", if (virAsprintf(&hostnet_name, "%s.%d",
qemuNetTypeToHostNet(net->type), qemuNetTypeToHostNet(net->type),
hostnet_index) < 0) { hostnet_index) < 0) {
virReportOOMError(NULL);
VIR_FREE(nic_name); VIR_FREE(nic_name);
return -1; return -1;
} }
@ -2434,7 +2449,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
hostdev->source.subsys.u.pci.function); hostdev->source.subsys.u.pci.function);
if (ret < 0) { if (ret < 0) {
pcidev = NULL; pcidev = NULL;
goto error; goto no_memory;
} }
ADD_ARG_LIT("-pcidevice"); ADD_ARG_LIT("-pcidevice");
ADD_ARG_LIT(pcidev); ADD_ARG_LIT(pcidev);
@ -2589,6 +2604,7 @@ no_memory:
for (i = 0 ; i < argcount ; i++) for (i = 0 ; i < argcount ; i++)
VIR_FREE(arglist[i]); VIR_FREE(arglist[i]);
VIR_FREE(arglist); VIR_FREE(arglist);
virReportOOMError(NULL);
return -1; return -1;
} }
@ -3177,12 +3193,19 @@ qemuParseCommandLineChr(virConnectPtr conn,
def->data.udp.connectHost = strndup(val, svc1-val); def->data.udp.connectHost = strndup(val, svc1-val);
else else
def->data.udp.connectHost = strdup(val); def->data.udp.connectHost = strdup(val);
if (!def->data.udp.connectHost)
goto no_memory;
if (svc1) { if (svc1) {
svc1++; svc1++;
if (host2) if (host2)
def->data.udp.connectService = strndup(svc1, host2-svc1); def->data.udp.connectService = strndup(svc1, host2-svc1);
else else
def->data.udp.connectService = strdup(svc1); def->data.udp.connectService = strdup(svc1);
if (!def->data.udp.connectService)
goto no_memory;
} }
if (host2) { if (host2) {
@ -3191,10 +3214,15 @@ qemuParseCommandLineChr(virConnectPtr conn,
def->data.udp.bindHost = strndup(host2, svc2-host2); def->data.udp.bindHost = strndup(host2, svc2-host2);
else else
def->data.udp.bindHost = strdup(host2); def->data.udp.bindHost = strdup(host2);
if (!def->data.udp.bindHost)
goto no_memory;
} }
if (svc2) { if (svc2) {
svc2++; svc2++;
def->data.udp.bindService = strdup(svc2); def->data.udp.bindService = strdup(svc2);
if (!def->data.udp.bindService)
goto no_memory;
} }
} else if (STRPREFIX(val, "tcp:") || } else if (STRPREFIX(val, "tcp:") ||
STRPREFIX(val, "telnet:")) { STRPREFIX(val, "telnet:")) {
@ -3217,12 +3245,16 @@ qemuParseCommandLineChr(virConnectPtr conn,
def->data.tcp.listen = 1; def->data.tcp.listen = 1;
def->data.tcp.host = strndup(val, svc-val); def->data.tcp.host = strndup(val, svc-val);
if (!def->data.tcp.host)
goto no_memory;
svc++; svc++;
if (opt) { if (opt) {
def->data.tcp.service = strndup(svc, opt-svc); def->data.tcp.service = strndup(svc, opt-svc);
} else { } else {
def->data.tcp.service = strdup(svc); def->data.tcp.service = strdup(svc);
} }
if (!def->data.tcp.service)
goto no_memory;
} else if (STRPREFIX(val, "unix:")) { } else if (STRPREFIX(val, "unix:")) {
const char *opt; const char *opt;
val += strlen("unix:"); val += strlen("unix:");

View File

@ -364,17 +364,13 @@ qemudSecurityCapsInit(virSecurityDriverPtr secdrv,
caps->host.secModel.model = strdup(model); caps->host.secModel.model = strdup(model);
if (!caps->host.secModel.model) { if (!caps->host.secModel.model) {
char ebuf[1024]; virReportOOMError(NULL);
VIR_ERROR(_("Failed to copy secModel model: %s"),
virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }
caps->host.secModel.doi = strdup(doi); caps->host.secModel.doi = strdup(doi);
if (!caps->host.secModel.doi) { if (!caps->host.secModel.doi) {
char ebuf[1024]; virReportOOMError(NULL);
VIR_ERROR(_("Failed to copy secModel DOI: %s"),
virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }
@ -5851,8 +5847,10 @@ static struct qemuStreamMigFile *qemuStreamMigOpen(virStreamPtr st,
int timeout = 3; int timeout = 3;
int ret; int ret;
if (VIR_ALLOC(qemust) < 0) if (VIR_ALLOC(qemust) < 0) {
virReportOOMError(st->conn);
return NULL; return NULL;
}
qemust->fd = socket(AF_UNIX, SOCK_STREAM, 0); qemust->fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (qemust->fd < 0) if (qemust->fd < 0)

View File

@ -201,8 +201,10 @@ qemuMonitorSend(const virDomainObjPtr vm,
size_t len; size_t len;
int ret = -1; int ret = -1;
if (virAsprintf(&full, "%s\r", cmd) < 0) if (virAsprintf(&full, "%s\r", cmd) < 0) {
virReportOOMError(NULL);
return -1; return -1;
}
len = strlen(full); len = strlen(full);

View File

@ -870,12 +870,12 @@ doRemoteOpen (virConnectPtr conn,
} }
if(VIR_ALLOC(priv->callbackList)<0) { if(VIR_ALLOC(priv->callbackList)<0) {
error(conn, VIR_ERR_INVALID_ARG, _("Error allocating callbacks list")); virReportOOMError(conn);
goto failed; goto failed;
} }
if(VIR_ALLOC(priv->domainEvents)<0) { if(VIR_ALLOC(priv->domainEvents)<0) {
error(conn, VIR_ERR_INVALID_ARG, _("Error allocating domainEvents")); virReportOOMError(conn);
goto failed; goto failed;
} }
@ -2751,9 +2751,18 @@ remoteListDefinedDomains (virConnectPtr conn, char **const names, int maxnames)
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -3086,7 +3095,7 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain,
/* Serialise the scheduler parameters. */ /* Serialise the scheduler parameters. */
args.params.params_len = nparams; args.params.params_len = nparams;
if (VIR_ALLOC_N(args.params.params_val, nparams) < 0) { 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; goto done;
} }
@ -3432,9 +3441,18 @@ remoteListNetworks (virConnectPtr conn, char **const names, int maxnames)
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -3505,9 +3523,18 @@ remoteListDefinedNetworks (virConnectPtr conn,
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -3921,9 +3948,18 @@ remoteListInterfaces (virConnectPtr conn, char **const names, int maxnames)
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -3993,9 +4029,18 @@ remoteListDefinedInterfaces (virConnectPtr conn, char **const names, int maxname
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -4314,9 +4359,18 @@ remoteListStoragePools (virConnectPtr conn, char **const names, int maxnames)
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -4383,9 +4437,18 @@ remoteListDefinedStoragePools (virConnectPtr conn,
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -4890,9 +4953,18 @@ remoteStoragePoolListVolumes (virStoragePoolPtr pool, char **const names, int ma
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -5290,9 +5362,18 @@ static int remoteNodeListDevices(virConnectPtr conn,
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -5443,9 +5524,18 @@ static int remoteNodeDeviceListCaps(virNodeDevicePtr dev,
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.names.names_len;
cleanup: cleanup:
@ -6496,9 +6586,18 @@ remoteSecretListSecrets (virConnectPtr conn, char **uuids, int maxuuids)
* names and the list of pointers, so we have to strdup the * names and the list of pointers, so we have to strdup the
* names here. * 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]); 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; rv = ret.uuids.uuids_len;
cleanup: cleanup:
@ -6707,8 +6806,10 @@ remoteStreamOpen(virStreamPtr st,
struct private_data *priv = st->conn->privateData; struct private_data *priv = st->conn->privateData;
struct private_stream_data *stpriv; struct private_stream_data *stpriv;
if (VIR_ALLOC(stpriv) < 0) if (VIR_ALLOC(stpriv) < 0) {
virReportOOMError(st->conn);
return NULL; return NULL;
}
/* Initialize call object used to receive replies */ /* Initialize call object used to receive replies */
stpriv->proc_nr = proc_nr; stpriv->proc_nr = proc_nr;
@ -7106,8 +7207,10 @@ prepareCall(virConnectPtr conn,
struct remote_message_header hdr; struct remote_message_header hdr;
struct remote_thread_call *rv; struct remote_thread_call *rv;
if (VIR_ALLOC(rv) < 0) if (VIR_ALLOC(rv) < 0) {
virReportOOMError(conn);
return NULL; return NULL;
}
if (virCondInit(&rv->cond) < 0) { if (virCondInit(&rv->cond) < 0) {
VIR_FREE(rv); VIR_FREE(rv);

View File

@ -449,8 +449,10 @@ secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver,
if (secretLoadValidateUUID(conn, def, xml_basename) < 0) if (secretLoadValidateUUID(conn, def, xml_basename) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC(secret) < 0) if (VIR_ALLOC(secret) < 0) {
virReportOOMError(conn);
goto cleanup; goto cleanup;
}
secret->def = def; secret->def = def;
def = NULL; def = NULL;
@ -578,8 +580,10 @@ secretListSecrets(virConnectPtr conn, char **uuids, int maxuuids)
char *uuidstr; char *uuidstr;
if (i == maxuuids) if (i == maxuuids)
break; 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; goto cleanup;
}
virUUIDFormat(secret->def->uuid, uuidstr); virUUIDFormat(secret->def->uuid, uuidstr);
uuids[i] = uuidstr; uuids[i] = uuidstr;
i++; i++;

View File

@ -56,13 +56,16 @@ profile_status(const char *str, const int check_enforcing)
int rc = -1; int rc = -1;
/* create string that is '<str> \0' for accurate matching */ /* 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; return rc;
}
if (check_enforcing != 0) { if (check_enforcing != 0) {
/* create string that is '<str> (enforce)\0' for accurate matching */ /* create string that is '<str> (enforce)\0' for accurate matching */
if (virAsprintf(&etmp, "%s (enforce)", str) == -1) { if (virAsprintf(&etmp, "%s (enforce)", str) == -1) {
VIR_FREE(tmp); VIR_FREE(tmp);
virReportOOMError(NULL);
return rc; return rc;
} }
} }

View File

@ -326,6 +326,14 @@ getNewStyleBlockDevice(virConnectPtr conn,
} }
*block_device = strdup(block_dirent->d_name); *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); VIR_DEBUG(_("Block device is '%s'"), *block_device);
break; break;
@ -360,9 +368,16 @@ getOldStyleBlockDevice(virConnectPtr conn,
blockp++; blockp++;
*block_device = strdup(blockp); *block_device = strdup(blockp);
if (*block_device == NULL) {
virReportOOMError(conn);
retval = -1;
goto out;
}
VIR_DEBUG(_("Block device is '%s'"), *block_device); VIR_DEBUG(_("Block device is '%s'"), *block_device);
} }
out:
return retval; return retval;
} }

View File

@ -388,6 +388,10 @@ virConfParseString(virConfParserCtxtPtr ctxt)
return(NULL); return(NULL);
} }
ret = strndup(base, ctxt->cur - base); ret = strndup(base, ctxt->cur - base);
if (ret == NULL) {
virReportOOMError(NULL);
return NULL;
}
NEXT; NEXT;
} else if ((ctxt->cur + 6 < ctxt->end) && (ctxt->cur[0] == '"') && } else if ((ctxt->cur + 6 < ctxt->end) && (ctxt->cur[0] == '"') &&
(ctxt->cur[1] == '"') && (ctxt->cur[2] == '"')) { (ctxt->cur[1] == '"') && (ctxt->cur[2] == '"')) {
@ -404,6 +408,10 @@ virConfParseString(virConfParserCtxtPtr ctxt)
return(NULL); return(NULL);
} }
ret = strndup(base, ctxt->cur - base); ret = strndup(base, ctxt->cur - base);
if (ret == NULL) {
virReportOOMError(NULL);
return NULL;
}
ctxt->cur += 3; ctxt->cur += 3;
} else if (CUR == '"') { } else if (CUR == '"') {
NEXT; NEXT;
@ -415,6 +423,10 @@ virConfParseString(virConfParserCtxtPtr ctxt)
return(NULL); return(NULL);
} }
ret = strndup(base, ctxt->cur - base); ret = strndup(base, ctxt->cur - base);
if (ret == NULL) {
virReportOOMError(NULL);
return NULL;
}
NEXT; NEXT;
} }
return(ret); return(ret);
@ -857,11 +869,13 @@ virConfSetValue (virConfPtr conf,
if (!cur) { if (!cur) {
if (VIR_ALLOC(cur) < 0) { if (VIR_ALLOC(cur) < 0) {
virReportOOMError(NULL);
virConfFreeValue(value); virConfFreeValue(value);
return (-1); return (-1);
} }
cur->comment = NULL; cur->comment = NULL;
if (!(cur->name = strdup(setting))) { if (!(cur->name = strdup(setting))) {
virReportOOMError(NULL);
virConfFreeValue(value); virConfFreeValue(value);
VIR_FREE(cur); VIR_FREE(cur);
return (-1); return (-1);

View File

@ -1333,13 +1333,18 @@ cleanup:
return ret; return ret;
} }
static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { static char *vboxDomainGetOSType(virDomainPtr dom) {
/* Returning "hvm" always as suggested on list, cause /* Returning "hvm" always as suggested on list, cause
* this functions seems to be badly named and it * this functions seems to be badly named and it
* is supposed to pass the ABI name and not the domain * is supposed to pass the ABI name and not the domain
* operating system driver as I had imagined ;) * 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) { static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory) {
@ -1881,7 +1886,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
if (valueDisplayUtf8) if (valueDisplayUtf8)
sdlDisplay = strdup(valueDisplayUtf8); sdlDisplay = strdup(valueDisplayUtf8);
if (sdlDisplay == NULL) { 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 /* just don't go to cleanup yet as it is ok to have
* sdlDisplay as NULL and we check it below if it * sdlDisplay as NULL and we check it below if it
* exist and then only use it there * exist and then only use it there
@ -1895,7 +1900,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
if (valueDisplayUtf8) if (valueDisplayUtf8)
guiDisplay = strdup(valueDisplayUtf8); guiDisplay = strdup(valueDisplayUtf8);
if (guiDisplay == NULL) { 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 /* just don't go to cleanup yet as it is ok to have
* guiDisplay as NULL and we check it below if it * guiDisplay as NULL and we check it below if it
* exist and then only use it there * exist and then only use it there
@ -1932,7 +1937,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP; def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
def->graphics[def->ngraphics]->data.desktop.display = strdup(getenv("DISPLAY")); def->graphics[def->ngraphics]->data.desktop.display = strdup(getenv("DISPLAY"));
if (def->graphics[def->ngraphics]->data.desktop.display == NULL) { 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 /* just don't go to cleanup yet as it is ok to have
* display as NULL * display as NULL
*/ */
@ -3983,6 +3988,11 @@ static int vboxDomainAttachDevice(virDomainPtr dom, const char *xml) {
def->os.type = strdup("hvm"); def->os.type = strdup("hvm");
if (def->os.type == NULL) {
virReportOOMError(dom->conn);
goto cleanup;
}
dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml, dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml,
VIR_DOMAIN_XML_INACTIVE); VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) { if (dev == NULL) {
@ -4176,6 +4186,11 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) {
def->os.type = strdup("hvm"); def->os.type = strdup("hvm");
if (def->os.type == NULL) {
virReportOOMError(dom->conn);
goto cleanup;
}
dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml, dev = virDomainDeviceDefParse(dom->conn, data->caps, def, xml,
VIR_DOMAIN_XML_INACTIVE); VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) { if (dev == NULL) {

View File

@ -138,14 +138,20 @@ xenDomainUsedCpus(virDomainPtr dom)
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0) if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return(NULL); return(NULL);
if (VIR_ALLOC_N(cpulist, priv->nbNodeCpus) < 0) if (VIR_ALLOC_N(cpulist, priv->nbNodeCpus) < 0) {
virReportOOMError(dom->conn);
goto done; goto done;
if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) }
if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) {
virReportOOMError(dom->conn);
goto done; goto done;
}
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
if (xalloc_oversized(nb_vcpu, cpumaplen) || 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; goto done;
}
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu, if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
cpumap, cpumaplen)) >= 0) { cpumap, cpumaplen)) >= 0) {

View File

@ -1114,11 +1114,15 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams)
switch (op.u.getschedulerid.sched_id){ switch (op.u.getschedulerid.sched_id){
case XEN_SCHEDULER_SEDF: case XEN_SCHEDULER_SEDF:
schedulertype = strdup("sedf"); schedulertype = strdup("sedf");
if (schedulertype == NULL)
virReportOOMError(domain->conn);
if (nparams) if (nparams)
*nparams = 6; *nparams = 6;
break; break;
case XEN_SCHEDULER_CREDIT: case XEN_SCHEDULER_CREDIT:
schedulertype = strdup("credit"); schedulertype = strdup("credit");
if (schedulertype == NULL)
virReportOOMError(domain->conn);
if (nparams) if (nparams)
*nparams = 2; *nparams = 2;
break; break;
@ -2755,6 +2759,7 @@ xenHypervisorDomainGetOSType (virDomainPtr dom)
{ {
xenUnifiedPrivatePtr priv; xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo; xen_getdomaininfo dominfo;
char *ostype = NULL;
priv = (xenUnifiedPrivatePtr) dom->conn->privateData; priv = (xenUnifiedPrivatePtr) dom->conn->privateData;
if (priv->handle < 0) if (priv->handle < 0)
@ -2774,8 +2779,14 @@ xenHypervisorDomainGetOSType (virDomainPtr dom)
return (NULL); return (NULL);
if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM) if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM)
return strdup("hvm"); ostype = strdup("hvm");
return strdup("linux"); else
ostype = strdup("linux");
if (ostype == NULL)
virReportOOMError(dom->conn);
return ostype;
} }
virDomainPtr virDomainPtr

View File

@ -107,6 +107,7 @@ xenInotifyXenCacheLookup(virConnectPtr conn,
if (!*name) { if (!*name) {
DEBUG0("Error getting dom from def"); DEBUG0("Error getting dom from def");
virReportOOMError(conn);
return -1; return -1;
} }
return 0; return 0;
@ -145,8 +146,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename,
if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) { if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
*name = strdup(priv->configInfoList->doms[i]->name); *name = strdup(priv->configInfoList->doms[i]->name);
if (!*name) { if (!*name) {
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR, virReportOOMError(conn);
_("finding dom for %s"), uuid_str);
return -1; return -1;
} }
memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN); memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN);
@ -159,8 +159,10 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename,
return -1; return -1;
} }
if (!(*name = strdup(dom->name))) if (!(*name = strdup(dom->name))) {
virReportOOMError(conn);
return -1; return -1;
}
memcpy(uuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(uuid, dom->uuid, VIR_UUID_BUFLEN);
virDomainFree(dom); virDomainFree(dom);
/* succeeded too find domain by uuid */ /* succeeded too find domain by uuid */
@ -380,7 +382,7 @@ cleanup:
* Returns 0 or -1 in case of error. * Returns 0 or -1 in case of error.
*/ */
virDrvOpenStatus virDrvOpenStatus
xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED, xenInotifyOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
@ -397,8 +399,7 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
priv->useXenConfigCache = 0; priv->useXenConfigCache = 0;
if (VIR_ALLOC(priv->configInfoList) < 0) { if (VIR_ALLOC(priv->configInfoList) < 0) {
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR, virReportOOMError(conn);
"%s", _("failed to allocate configInfoList"));
return -1; return -1;
} }

View File

@ -1055,8 +1055,13 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
"%s", _("domain information incomplete, missing name")); "%s", _("domain information incomplete, missing name"));
goto error; goto error;
} }
if (domname) if (domname) {
*domname = strdup(name); *domname = strdup(name);
if (*domname == NULL) {
virReportOOMError(xend);
goto error;
}
}
if (sexpr_uuid(uuid, root, "domain/uuid") < 0) { if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR, virXendError(xend, VIR_ERR_INTERNAL_ERROR,
@ -2946,8 +2951,10 @@ xenDaemonOpen(virConnectPtr conn,
goto failed; goto failed;
} else if (STRCASEEQ (conn->uri->scheme, "http")) { } else if (STRCASEEQ (conn->uri->scheme, "http")) {
if (conn->uri->port && if (conn->uri->port &&
virAsprintf(&port, "%d", conn->uri->port) == -1) virAsprintf(&port, "%d", conn->uri->port) == -1) {
virReportOOMError(conn);
goto failed; goto failed;
}
if (xenDaemonOpen_tcp(conn, if (xenDaemonOpen_tcp(conn,
conn->uri->server ? conn->uri->server : "localhost", conn->uri->server ? conn->uri->server : "localhost",
@ -3164,6 +3171,9 @@ xenDaemonDomainGetOSType(virDomainPtr domain)
type = strdup("linux"); type = strdup("linux");
} }
if (type == NULL)
virReportOOMError(domain->conn);
sexpr_free(root); sexpr_free(root);
return(type); return(type);
@ -3959,6 +3969,10 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
if (id >= 0) { if (id >= 0) {
if (!memcmp(uuid, ident, VIR_UUID_BUFLEN)) { if (!memcmp(uuid, ident, VIR_UUID_BUFLEN)) {
name = strdup(*tmp); name = strdup(*tmp);
if (name == NULL)
virReportOOMError(conn);
break; break;
} }
} }
@ -3979,7 +3993,14 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
id = sexpr_int(root, "domain/domid"); id = sexpr_int(root, "domain/domid");
else else
id = -1; id = -1;
name = domname ? strdup(domname) : NULL;
if (domname) {
name = strdup(domname);
if (name == NULL)
virReportOOMError(conn);
}
sexpr_free(root); sexpr_free(root);
} }
@ -4308,8 +4329,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
autonode->u.s.car->u.value = (autostart ? strdup("start") autonode->u.s.car->u.value = (autostart ? strdup("start")
: strdup("ignore")); : strdup("ignore"));
if (!(autonode->u.s.car->u.value)) { if (!(autonode->u.s.car->u.value)) {
virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR, virReportOOMError(domain->conn);
"%s", _("no memory"));
goto error; goto error;
} }
@ -4628,7 +4648,7 @@ error:
static int static int
xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) { xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
struct sexpr *root = NULL; struct sexpr *root = NULL;
int ret = -1; int i, ret = -1;
struct sexpr *_for_i, *node; struct sexpr *_for_i, *node;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
@ -4651,12 +4671,19 @@ xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
if (node->kind != SEXPR_VALUE) if (node->kind != SEXPR_VALUE)
continue; continue;
names[ret++] = strdup(node->u.value); if ((names[ret++] = strdup(node->u.value)) == NULL) {
virReportOOMError(conn);
goto error;
}
if (ret >= maxnames) if (ret >= maxnames)
break; break;
} }
error: error:
for (i = 0; i < ret; ++i)
VIR_FREE(names[i]);
sexpr_free(root); sexpr_free(root);
return(ret); return(ret);
} }
@ -4708,14 +4735,14 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
if (STREQ (ret, "credit")) { if (STREQ (ret, "credit")) {
schedulertype = strdup("credit"); schedulertype = strdup("credit");
if (schedulertype == NULL){ if (schedulertype == NULL){
virXendError(domain->conn, VIR_ERR_SYSTEM_ERROR, "%s", _("strdup failed")); virReportOOMError(domain->conn);
goto error; goto error;
} }
*nparams = XEN_SCHED_CRED_NPARAM; *nparams = XEN_SCHED_CRED_NPARAM;
} else if (STREQ (ret, "sedf")) { } else if (STREQ (ret, "sedf")) {
schedulertype = strdup("sedf"); schedulertype = strdup("sedf");
if (schedulertype == NULL){ if (schedulertype == NULL){
virXendError(domain->conn, VIR_ERR_SYSTEM_ERROR, "%s", _("strdup failed")); virReportOOMError(domain->conn);
goto error; goto error;
} }
*nparams = XEN_SCHED_SEDF_NPARAM; *nparams = XEN_SCHED_SEDF_NPARAM;

View File

@ -689,8 +689,10 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
int i; int i;
const char *defaultArch, *defaultMachine; const char *defaultArch, *defaultMachine;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0) {
virReportOOMError(conn);
return NULL; return NULL;
}
def->virtType = VIR_DOMAIN_VIRT_XEN; def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1; def->id = -1;
@ -1100,7 +1102,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
} }
if (VIR_ALLOC(net) < 0) if (VIR_ALLOC(net) < 0)
goto cleanup; goto no_memory;
if (mac[0]) { if (mac[0]) {
unsigned int rawmac[6]; unsigned int rawmac[6];
@ -1234,7 +1236,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
goto skippci; goto skippci;
if (VIR_ALLOC(hostdev) < 0) if (VIR_ALLOC(hostdev) < 0)
goto cleanup; goto no_memory;
hostdev->managed = 0; hostdev->managed = 0;
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
@ -1922,8 +1924,10 @@ static
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) { int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (VIR_ALLOC(value) < 0) if (VIR_ALLOC(value) < 0) {
virReportOOMError(NULL);
return -1; return -1;
}
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
value->next = NULL; value->next = NULL;
@ -1937,13 +1941,16 @@ static
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) { int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (VIR_ALLOC(value) < 0) if (VIR_ALLOC(value) < 0) {
virReportOOMError(NULL);
return -1; return -1;
}
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->next = NULL; value->next = NULL;
if (!(value->str = strdup(str))) { if (!(value->str = strdup(str))) {
VIR_FREE(value); VIR_FREE(value);
virReportOOMError(NULL);
return -1; return -1;
} }
@ -2133,8 +2140,10 @@ xenXMDomainConfigFormatPCI(virConnectPtr conn,
if (!hasPCI) if (!hasPCI)
return 0; return 0;
if (VIR_ALLOC(pciVal) < 0) if (VIR_ALLOC(pciVal) < 0) {
virReportOOMError(conn);
return -1; return -1;
}
pciVal->type = VIR_CONF_LIST; pciVal->type = VIR_CONF_LIST;
pciVal->list = NULL; pciVal->list = NULL;
@ -2149,8 +2158,10 @@ xenXMDomainConfigFormatPCI(virConnectPtr conn,
def->hostdevs[i]->source.subsys.u.pci.domain, def->hostdevs[i]->source.subsys.u.pci.domain,
def->hostdevs[i]->source.subsys.u.pci.bus, def->hostdevs[i]->source.subsys.u.pci.bus,
def->hostdevs[i]->source.subsys.u.pci.slot, 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; goto error;
}
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf); VIR_FREE(buf);
@ -2748,6 +2759,7 @@ cleanup:
struct xenXMListIteratorContext { struct xenXMListIteratorContext {
virConnectPtr conn; virConnectPtr conn;
int oom;
int max; int max;
int count; int count;
char ** names; char ** names;
@ -2757,13 +2769,18 @@ static void xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const char *name,
struct xenXMListIteratorContext *ctx = data; struct xenXMListIteratorContext *ctx = data;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
if (ctx->oom)
return;
if (ctx->count == ctx->max) if (ctx->count == ctx->max)
return; return;
dom = xenDaemonLookupByName(ctx->conn, name); dom = xenDaemonLookupByName(ctx->conn, name);
if (!dom) { if (!dom) {
ctx->names[ctx->count] = strdup(name); if (!(ctx->names[ctx->count] = strdup(name)))
ctx->count++; ctx->oom = 1;
else
ctx->count++;
} else { } else {
virDomainFree(dom); virDomainFree(dom);
} }
@ -2777,7 +2794,7 @@ static void xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const char *name,
int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) { int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
xenUnifiedPrivatePtr priv; xenUnifiedPrivatePtr priv;
struct xenXMListIteratorContext ctx; struct xenXMListIteratorContext ctx;
int ret = -1; int i, ret = -1;
if (!VIR_IS_CONNECT(conn)) { if (!VIR_IS_CONNECT(conn)) {
xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -2794,11 +2811,21 @@ int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
maxnames = virHashSize(priv->configCache); maxnames = virHashSize(priv->configCache);
ctx.conn = conn; ctx.conn = conn;
ctx.oom = 0;
ctx.count = 0; ctx.count = 0;
ctx.max = maxnames; ctx.max = maxnames;
ctx.names = names; ctx.names = names;
virHashForEach(priv->nameConfigMap, xenXMListIterator, &ctx); 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; ret = ctx.count;
cleanup: cleanup:

View File

@ -305,17 +305,15 @@ xenStoreOpen(virConnectPtr conn,
#ifndef PROXY #ifndef PROXY
/* Init activeDomainList */ /* Init activeDomainList */
if (VIR_ALLOC(priv->activeDomainList) < 0) { if (VIR_ALLOC(priv->activeDomainList) < 0) {
virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR, virReportOOMError(conn);
"%s", _("failed to allocate activeDomainList"));
return -1; return -1;
} }
/* Init watch list before filling in domInfoList, /* Init watch list before filling in domInfoList,
so we can know if it is the first time through so we can know if it is the first time through
when the callback fires */ when the callback fires */
if ( VIR_ALLOC(priv->xsWatchList) < 0 ) { if (VIR_ALLOC(priv->xsWatchList) < 0) {
virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR, virReportOOMError(conn);
"%s", _("failed to allocate xsWatchList"));
return -1; return -1;
} }
@ -892,7 +890,8 @@ xenStoreDomainGetOSTypeID(virConnectPtr conn, int id) {
} }
if (str == NULL) if (str == NULL)
str = strdup("linux"); str = strdup("linux");
if (str == NULL)
virReportOOMError(conn);
return (str); return (str);
} }
@ -944,6 +943,10 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
if (match) { if (match) {
ret = strdup(list[i]); ret = strdup(list[i]);
if (ret == NULL)
virReportOOMError(conn);
break; break;
} }
} }
@ -995,15 +998,19 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) {
if (val == NULL) if (val == NULL)
break; break;
if ((devlen != len) || memcmp(val, dev, len)) { if ((devlen != len) || memcmp(val, dev, len)) {
free (val); VIR_FREE (val);
} else { } else {
ret = strdup(list[i]); ret = strdup(list[i]);
free (val);
free (list); if (ret == NULL)
virReportOOMError(conn);
VIR_FREE (val);
VIR_FREE (list);
return (ret); return (ret);
} }
} }
free (list); VIR_FREE (list);
} }
snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id); snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id);
list = xs_directory(priv->xshandle, 0, dir, &num); list = xs_directory(priv->xshandle, 0, dir, &num);
@ -1014,15 +1021,19 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) {
if (val == NULL) if (val == NULL)
break; break;
if ((devlen != len) || memcmp(val, dev, len)) { if ((devlen != len) || memcmp(val, dev, len)) {
free (val); VIR_FREE (val);
} else { } else {
ret = strdup(list[i]); ret = strdup(list[i]);
free (val);
free (list); if (ret == NULL)
virReportOOMError(conn);
VIR_FREE (val);
VIR_FREE (list);
return (ret); return (ret);
} }
} }
free (list); VIR_FREE (list);
} }
return (NULL); return (NULL);
} }
@ -1100,7 +1111,7 @@ int xenStoreAddWatch(virConnectPtr conn,
xenStoreWatchCallback cb, xenStoreWatchCallback cb,
void *opaque) void *opaque)
{ {
xenStoreWatchPtr watch; xenStoreWatchPtr watch = NULL;
int n; int n;
xenStoreWatchListPtr list; xenStoreWatchListPtr list;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
@ -1123,25 +1134,38 @@ int xenStoreAddWatch(virConnectPtr conn,
} }
if (VIR_ALLOC(watch) < 0) if (VIR_ALLOC(watch) < 0)
return -1; goto no_memory;
watch->path = strdup(path); watch->path = strdup(path);
watch->token = strdup(token); watch->token = strdup(token);
watch->cb = cb; watch->cb = cb;
watch->opaque = opaque; watch->opaque = opaque;
if (watch->path == NULL || watch->token == NULL) {
goto no_memory;
}
/* Make space on list */ /* Make space on list */
n = list->count; n = list->count;
if (VIR_REALLOC_N(list->watches, n + 1) < 0) { if (VIR_REALLOC_N(list->watches, n + 1) < 0) {
virXenStoreError(NULL, VIR_ERR_INTERNAL_ERROR, goto no_memory;
"%s", _("reallocating list"));
VIR_FREE(watch);
return -1;
} }
list->watches[n] = watch; list->watches[n] = watch;
list->count++; list->count++;
return xs_watch(priv->xshandle, watch->path, watch->token); 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;
} }
/* /*