On 2013年01月17日 01:17, Jim Fehlig wrote:
Osier Yang wrote:
On 2013年01月16日 07:15, Jim Fehlig wrote:
If building the libxl domain config fails, cleanup before returning
failure.
---
src/libxl/libxl_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index baa05e8..6da0272 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -769,7 +769,7 @@ libxlVmStart(libxlDriverPrivatePtr driver,
virDomainObjPtr vm,
libxl_domain_config_init(&d_config);
if (libxlBuildDomainConfig(driver, vm->def,&d_config)< 0)
- return -1;
+ goto error;
if (libxlFreeMem(priv,&d_config)< 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
vm->hasManagedSave = false;
}
VIR_FREE(managed_save_path);
This can be removed. It's freed in "error". But I'm fine if you keep it
there when pushing. ACK
But managed_save_path would be leaked on success then.
Oh, okay, I see. But after looking at the codes one more step.
libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml);
VIR_FORCE_CLOSE(managed_save_fd);
return 0;
error:
if (domid > 0) {
libxl_domain_destroy(priv->ctx, domid, NULL);
vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_FAILED);
}
libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml);
VIR_FREE(managed_save_path);
virDomainDefFree(def);
VIR_FORCE_CLOSE(managed_save_fd);
return -1;
I see this can be simplified as (not looking through all the
codes, so the 'ret < 0' checking might be not correct, but it
shows the idea):
ret = 0;
cleanup:
if (ret < 0 && domid > 0) {
libxl_domain_destroy(priv->ctx, domid, NULL);
vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_FAILED);
}
libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml);
VIR_FREE(managed_save_path);
if (ret < 0)
virDomainDefFree(def);
VIR_FORCE_CLOSE(managed_save_fd);
return ret;
And thus the previous "VIR_FREE(managed_save_path);" can be avoided.
Regards,
Osier
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list