Fix more OOM handling bugs

* src/qemu_conf.c: Fix leak of values upon OOM
* src/xend_internal.c: Fix missing check for OOM failure
* tests/qemuargv2xmltest.c, tests/qemuxml2argvtest.c: Free
  stateDir upon exit to avoid leak
This commit is contained in:
Daniel P. Berrange 2009-09-03 17:37:45 +01:00
parent 755915ea4b
commit cbe63e529d
4 changed files with 26 additions and 3 deletions

View File

@ -1848,6 +1848,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
continue; continue;
} }
ADD_ARG_SPACE;
if (idx < 0) { if (idx < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("unsupported disk type '%s'"), disk->dst); _("unsupported disk type '%s'"), disk->dst);
@ -1905,7 +1907,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
optstr = virBufferContentAndReset(&opt); optstr = virBufferContentAndReset(&opt);
ADD_ARG_LIT("-drive"); if ((qargv[qargc++] = strdup("-drive")) == NULL) {
VIR_FREE(optstr);
goto no_memory;
}
ADD_ARG(optstr); ADD_ARG(optstr);
} }
} else { } else {
@ -1961,6 +1966,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
net->vlan = i; net->vlan = i;
ADD_ARG_SPACE;
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) && if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
qemuAssignNetNames(def, net) < 0) qemuAssignNetNames(def, net) < 0)
goto no_memory; goto no_memory;
@ -1968,9 +1974,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
if (qemuBuildNicStr(conn, net, NULL, ',', net->vlan, &nic) < 0) if (qemuBuildNicStr(conn, net, NULL, ',', net->vlan, &nic) < 0)
goto error; goto error;
ADD_ARG_LIT("-net"); if ((qargv[qargc++] = strdup("-net")) == NULL) {
VIR_FREE(nic);
goto no_memory;
}
ADD_ARG(nic); ADD_ARG(nic);
ADD_ARG_SPACE;
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK || if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
int tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags); int tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags);
@ -1994,7 +2005,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto error; goto error;
} }
ADD_ARG_LIT("-net"); if ((qargv[qargc++] = strdup("-net")) == NULL) {
VIR_FREE(host);
goto no_memory;
}
ADD_ARG(host); ADD_ARG(host);
VIR_FREE(tapfd_name); VIR_FREE(tapfd_name);
@ -2362,6 +2376,7 @@ static int qemuStringToArgvEnv(const char *args,
goto no_memory; goto no_memory;
for (i = 0 ; i < envend ; i++) { for (i = 0 ; i < envend ; i++) {
progenv[i] = arglist[i]; progenv[i] = arglist[i];
arglist[i] = NULL;
} }
progenv[i] = NULL; progenv[i] = NULL;
} }

View File

@ -5226,6 +5226,9 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
break; break;
} }
if (virBufferError(buf))
return -1;
return 0; return 0;
} }
@ -5549,6 +5552,9 @@ xenDaemonFormatSxprSound(virConnectPtr conn,
virBufferVSprintf(buf, "%s%s", i ? "," : "", str); virBufferVSprintf(buf, "%s%s", i ? "," : "", str);
} }
if (virBufferError(buf))
return -1;
return 0; return 0;
} }

View File

@ -223,6 +223,7 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat"); DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000"); DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
free(driver.stateDir);
virCapabilitiesFree(driver.caps); virCapabilitiesFree(driver.caps);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);

View File

@ -280,6 +280,7 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat"); DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000"); DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
free(driver.stateDir);
virCapabilitiesFree(driver.caps); virCapabilitiesFree(driver.caps);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);