VBox fix minor bugs in display and added OOM checks

* src/vbox/vbox_tmpl.c: minor bug in selecting the graphics type. if the
  graphics type was desktop it was assumed that display is set for it,
  and thus crashed on strdup. Also adds a number of missing OOM checks.
This commit is contained in:
Pritesh Kothari 2009-09-07 17:44:12 +02:00 committed by Daniel Veillard
parent 9323717b47
commit 089ef25a85

View File

@ -1836,13 +1836,16 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
def->videos[0]->type = VIR_DOMAIN_VIDEO_TYPE_VBOX; def->videos[0]->type = VIR_DOMAIN_VIDEO_TYPE_VBOX;
def->videos[0]->vram = VRAMSize; def->videos[0]->vram = VRAMSize;
def->videos[0]->heads = monitorCount; def->videos[0]->heads = monitorCount;
if (VIR_ALLOC(def->videos[0]->accel)) { if (VIR_ALLOC(def->videos[0]->accel) >= 0) {
def->videos[0]->accel->support3d = accelerate3DEnabled; def->videos[0]->accel->support3d = accelerate3DEnabled;
/* Not supported yet, but should be in 3.1 soon */ /* Not supported yet, but should be in 3.1 soon */
def->videos[0]->accel->support2d = 0; def->videos[0]->accel->support2d = 0;
} } else
} virReportOOMError(dom->conn);
} } else
virReportOOMError(dom->conn);
} else
virReportOOMError(dom->conn);
} }
/* dump display options vrdp/gui/sdl */ /* dump display options vrdp/gui/sdl */
@ -1996,7 +1999,8 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
} }
def->ngraphics++; def->ngraphics++;
} } else
virReportOOMError(dom->conn);
} }
VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer); VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
} }
@ -2027,7 +2031,8 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK; def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK;
def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE; def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE;
def->disks[i]->type = VIR_DOMAIN_DISK_TYPE_FILE; def->disks[i]->type = VIR_DOMAIN_DISK_TYPE_FILE;
} } else
virReportOOMError(dom->conn);
} }
} }
@ -2117,7 +2122,8 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) { if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) {
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
if (VIR_ALLOC(def->nets[i]) >= 0) { if (VIR_ALLOC(def->nets[i]) >= 0) {
} } else
virReportOOMError(dom->conn);
} }
} }
@ -2250,9 +2256,11 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
} else { } else {
VIR_FREE(def->sounds); VIR_FREE(def->sounds);
def->nsounds = 0; def->nsounds = 0;
virReportOOMError(dom->conn);
} }
} else { } else {
def->nsounds = 0; def->nsounds = 0;
virReportOOMError(dom->conn);
} }
} }
audioAdapter->vtbl->nsisupports.Release((nsISupports *)audioAdapter); audioAdapter->vtbl->nsisupports.Release((nsISupports *)audioAdapter);
@ -2286,9 +2294,11 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
def->disks[def->ndisks - 1]->dst = strdup("hdc"); def->disks[def->ndisks - 1]->dst = strdup("hdc");
} else { } else {
def->ndisks--; def->ndisks--;
virReportOOMError(dom->conn);
} }
} else { } else {
def->ndisks--; def->ndisks--;
virReportOOMError(dom->conn);
} }
data->pFuncs->pfnUtf8Free(location); data->pFuncs->pfnUtf8Free(location);
@ -2331,9 +2341,11 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
def->disks[def->ndisks - 1]->dst = strdup("fda"); def->disks[def->ndisks - 1]->dst = strdup("fda");
} else { } else {
def->ndisks--; def->ndisks--;
virReportOOMError(dom->conn);
} }
} else { } else {
def->ndisks--; def->ndisks--;
virReportOOMError(dom->conn);
} }
data->pFuncs->pfnUtf8Free(location); data->pFuncs->pfnUtf8Free(location);
@ -2369,7 +2381,8 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= 0)) { if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= 0)) {
for (i = 0; i < def->nserials; i++) { for (i = 0; i < def->nserials; i++) {
if (VIR_ALLOC(def->serials[i]) >= 0) { if (VIR_ALLOC(def->serials[i]) >= 0) {
} } else
virReportOOMError(dom->conn);
} }
} }
@ -2444,7 +2457,8 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparallels) >= 0)) { if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparallels) >= 0)) {
for (i = 0; i < def->nparallels; i++) { for (i = 0; i < def->nparallels; i++) {
if (VIR_ALLOC(def->parallels[i]) >= 0) { if (VIR_ALLOC(def->parallels[i]) >= 0) {
} } else
virReportOOMError(dom->conn);
} }
} }
@ -2560,10 +2574,12 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
data->pFuncs->pfnUtf8Free(productIdUtf8); data->pFuncs->pfnUtf8Free(productIdUtf8);
USBFilterCount++; USBFilterCount++;
} } else
virReportOOMError(dom->conn);
} }
} }
} } else
virReportOOMError(dom->conn);
} }
} }
@ -3670,25 +3686,29 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) && (guiPresent == 0)) { if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) && (guiPresent == 0)) {
guiPresent = 1; guiPresent = 1;
guiDisplay = strdup(def->graphics[i]->data.desktop.display); if (def->graphics[i]->data.desktop.display) {
if (guiDisplay == NULL) { guiDisplay = strdup(def->graphics[i]->data.desktop.display);
vboxError(conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed"); if (guiDisplay == NULL) {
/* just don't go to cleanup yet as it is ok to have virReportOOMError(conn);
* guiDisplay as NULL and we check it below if it /* just don't go to cleanup yet as it is ok to have
* exist and then only use it there * guiDisplay as NULL and we check it below if it
*/ * exist and then only use it there
*/
}
} }
} }
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) && (sdlPresent == 0)) { if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) && (sdlPresent == 0)) {
sdlPresent = 1; sdlPresent = 1;
sdlDisplay = strdup(def->graphics[i]->data.sdl.display); if (def->graphics[i]->data.sdl.display) {
if (sdlDisplay == NULL) { sdlDisplay = strdup(def->graphics[i]->data.sdl.display);
vboxError(conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed"); if (sdlDisplay == NULL) {
/* just don't go to cleanup yet as it is ok to have virReportOOMError(conn);
* sdlDisplay as NULL and we check it below if it /* just don't go to cleanup yet as it is ok to have
* exist and then only use it there * sdlDisplay as NULL and we check it below if it
*/ * exist and then only use it there
*/
}
} }
} }
} }
@ -5488,6 +5508,7 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
data->pFuncs->pfnUtf16Free(toIPAddressUtf16); data->pFuncs->pfnUtf16Free(toIPAddressUtf16);
} else { } else {
def->nranges = 0; def->nranges = 0;
virReportOOMError(network->conn);
} }
def->nhosts = 1; def->nhosts = 1;