xenConfigGetString returns a newly-allocated pointer and it has to be
freed by the caller.
Signed-off-by: Fabiano FidĂȘncio <fidencio(a)redhat.com>
---
src/xenconfig/xen_common.c | 41 ++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index c044cb9672..ab4bb7ff3f 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -342,36 +342,43 @@ xenParseTimeOffset(virConfPtr conf, virDomainDefPtr def)
static int
xenParseEventsActions(virConfPtr conf, virDomainDefPtr def)
{
- const char *str = NULL;
+ const char *on_poweroff = NULL, *on_reboot = NULL, *on_crash = NULL;
+ int ret = -1;
- if (xenConfigGetString(conf, "on_poweroff", &str, "destroy")
< 0)
- return -1;
+ if (xenConfigGetString(conf, "on_poweroff", &on_poweroff,
"destroy") < 0)
+ goto cleanup;
- if ((def->onPoweroff = virDomainLifecycleActionTypeFromString(str)) < 0) {
+ if ((def->onPoweroff = virDomainLifecycleActionTypeFromString(on_poweroff)) <
0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected value %s for on_poweroff"), str);
- return -1;
+ _("unexpected value %s for on_poweroff"), on_poweroff);
+ goto cleanup;
}
- if (xenConfigGetString(conf, "on_reboot", &str, "restart")
< 0)
- return -1;
+ if (xenConfigGetString(conf, "on_reboot", &on_reboot,
"restart") < 0)
+ goto cleanup;
- if ((def->onReboot = virDomainLifecycleActionTypeFromString(str)) < 0) {
+ if ((def->onReboot = virDomainLifecycleActionTypeFromString(on_reboot)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected value %s for on_reboot"), str);
- return -1;
+ _("unexpected value %s for on_reboot"), on_reboot);
+ goto cleanup;
}
- if (xenConfigGetString(conf, "on_crash", &str, "restart")
< 0)
- return -1;
+ if (xenConfigGetString(conf, "on_crash", &on_crash,
"restart") < 0)
+ goto cleanup;
- if ((def->onCrash = virDomainLifecycleActionTypeFromString(str)) < 0) {
+ if ((def->onCrash = virDomainLifecycleActionTypeFromString(on_crash)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected value %s for on_crash"), str);
- return -1;
+ _("unexpected value %s for on_crash"), on_crash);
+ goto cleanup;
}
- return 0;
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(on_poweroff);
+ VIR_FREE(on_reboot);
+ VIR_FREE(on_crash);
+ return ret;
}
--
2.17.1