提交 50dc7015 编写于 作者: J John Ferlan 提交者: Michal Privoznik

parallels: Resolve some resource leaks

Be sure to VIR_FREE(accel) and moved virDomainVideoDefFree() within no_memory
label to be consistent

Resolve resource leak in parallelsApplyIfaceParams() when the 'oldnet' is
allocated locally. Also virCommandFree(cmd) as necessary.
上级 e3818b2a
...@@ -271,17 +271,17 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) ...@@ -271,17 +271,17 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
if (!(tmp = virJSONValueObjectGetString(value, "size"))) { if (!(tmp = virJSONValueObjectGetString(value, "size"))) {
parallelsParseError(); parallelsParseError();
goto cleanup; goto error;
} }
if (virStrToLong_ul(tmp, &endptr, 10, &mem) < 0) { if (virStrToLong_ul(tmp, &endptr, 10, &mem) < 0) {
parallelsParseError(); parallelsParseError();
goto cleanup; goto error;
} }
if (!STREQ(endptr, "Mb")) { if (!STREQ(endptr, "Mb")) {
parallelsParseError(); parallelsParseError();
goto cleanup; goto error;
} }
if (VIR_ALLOC(video) < 0) if (VIR_ALLOC(video) < 0)
...@@ -304,8 +304,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) ...@@ -304,8 +304,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
cleanup: VIR_FREE(accel);
virDomainVideoDefFree(video); virDomainVideoDefFree(video);
error:
return -1; return -1;
} }
...@@ -1645,7 +1646,7 @@ static int parallelsAddHddByVolume(parallelsDomObjPtr pdom, ...@@ -1645,7 +1646,7 @@ static int parallelsAddHddByVolume(parallelsDomObjPtr pdom,
virCommandAddArgFormat(cmd, "--position=%d", virCommandAddArgFormat(cmd, "--position=%d",
disk->info.addr.drive.target); disk->info.addr.drive.target);
if (virCommandRun(cmd, NULL)) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
if (parallelsStorageVolumeDefRemove(pool, voldef)) if (parallelsStorageVolumeDefRemove(pool, voldef))
...@@ -1793,9 +1794,10 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom, ...@@ -1793,9 +1794,10 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom,
{ {
bool create = false; bool create = false;
bool is_changed = false; bool is_changed = false;
virCommandPtr cmd; virCommandPtr cmd = NULL;
char strmac[VIR_MAC_STRING_BUFLEN]; char strmac[VIR_MAC_STRING_BUFLEN];
int i; int i;
int ret = -1;
if (!oldnet) { if (!oldnet) {
create = true; create = true;
...@@ -1808,58 +1810,58 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom, ...@@ -1808,58 +1810,58 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom,
if (!create && oldnet->type != newnet->type) { if (!create && oldnet->type != newnet->type) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Changing network type is not supported")); _("Changing network type is not supported"));
return -1; goto cleanup;
} }
if (!STREQ_NULLABLE(oldnet->model, newnet->model)) { if (!STREQ_NULLABLE(oldnet->model, newnet->model)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Changing network device model is not supported")); _("Changing network device model is not supported"));
return -1; goto cleanup;
} }
if (!STREQ_NULLABLE(oldnet->data.network.portgroup, if (!STREQ_NULLABLE(oldnet->data.network.portgroup,
newnet->data.network.portgroup)) { newnet->data.network.portgroup)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Changing network portgroup is not supported")); _("Changing network portgroup is not supported"));
return -1; goto cleanup;
} }
if (!virNetDevVPortProfileEqual(oldnet->virtPortProfile, if (!virNetDevVPortProfileEqual(oldnet->virtPortProfile,
newnet->virtPortProfile)) { newnet->virtPortProfile)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Changing virtual port profile is not supported")); _("Changing virtual port profile is not supported"));
return -1; goto cleanup;
} }
if (newnet->tune.sndbuf_specified) { if (newnet->tune.sndbuf_specified) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Setting send buffer size is not supported")); _("Setting send buffer size is not supported"));
return -1; goto cleanup;
} }
if (!STREQ_NULLABLE(oldnet->script, newnet->script)) { if (!STREQ_NULLABLE(oldnet->script, newnet->script)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Setting startup script is not supported")); _("Setting startup script is not supported"));
return -1; goto cleanup;
} }
if (!STREQ_NULLABLE(oldnet->filter, newnet->filter)) { if (!STREQ_NULLABLE(oldnet->filter, newnet->filter)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Changing filter params is not supported")); _("Changing filter params is not supported"));
return -1; goto cleanup;
} }
if (newnet->bandwidth != NULL) { if (newnet->bandwidth != NULL) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Setting bandwidth params is not supported")); _("Setting bandwidth params is not supported"));
return -1; goto cleanup;
} }
for (i = 0; i < sizeof(newnet->vlan); i++) { for (i = 0; i < sizeof(newnet->vlan); i++) {
if (((char *)&newnet->vlan)[i] != 0) { if (((char *)&newnet->vlan)[i] != 0) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Setting vlan params is not supported")); _("Setting vlan params is not supported"));
return -1; goto cleanup;
} }
} }
...@@ -1903,13 +1905,20 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom, ...@@ -1903,13 +1905,20 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom,
if (!create && !is_changed) { if (!create && !is_changed) {
/* nothing changed - no need to run prlctl */ /* nothing changed - no need to run prlctl */
return 0; ret = 0;
goto cleanup;
} }
if (virCommandRun(cmd, NULL)) if (virCommandRun(cmd, NULL) < 0)
return -1; goto cleanup;
return 0; ret = 0;
cleanup:
if (create)
VIR_FREE(oldnet);
virCommandFree(cmd);
return ret;
} }
static int static int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册