提交 1a53b2ba 编写于 作者: P Peter Krempa

cmdDomHostname: Fix uninitialized use of 'hostname' by refactoring cleanup

Use 'g_autoptr' which mandates initialization for 'hostname' and also
for 'domain' to allow full refactor of the cleanup path.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 140c756f
...@@ -11885,9 +11885,8 @@ VIR_ENUM_IMPL(virshDomainHostnameSource, ...@@ -11885,9 +11885,8 @@ VIR_ENUM_IMPL(virshDomainHostnameSource,
static bool static bool
cmdDomHostname(vshControl *ctl, const vshCmd *cmd) cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
{ {
char *hostname; g_autofree char *hostname = NULL;
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
bool ret = false;
const char *sourcestr = NULL; const char *sourcestr = NULL;
int flags = 0; /* Use default value. Drivers can have its own default. */ int flags = 0; /* Use default value. Drivers can have its own default. */
...@@ -11895,14 +11894,14 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) ...@@ -11895,14 +11894,14 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0) if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0)
goto error; return false;
if (sourcestr) { if (sourcestr) {
int source = virshDomainHostnameSourceTypeFromString(sourcestr); int source = virshDomainHostnameSourceTypeFromString(sourcestr);
if (source < 0) { if (source < 0) {
vshError(ctl, _("Unknown data source '%s'"), sourcestr); vshError(ctl, _("Unknown data source '%s'"), sourcestr);
goto error; return false;
} }
switch ((virshDomainHostnameSource) source) { switch ((virshDomainHostnameSource) source) {
...@@ -11920,16 +11919,11 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) ...@@ -11920,16 +11919,11 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
hostname = virDomainGetHostname(dom, flags); hostname = virDomainGetHostname(dom, flags);
if (hostname == NULL) { if (hostname == NULL) {
vshError(ctl, "%s", _("failed to get hostname")); vshError(ctl, "%s", _("failed to get hostname"));
goto error; return false;
} }
vshPrint(ctl, "%s\n", hostname); vshPrint(ctl, "%s\n", hostname);
ret = true; return true;
error:
VIR_FREE(hostname);
virshDomainFree(dom);
return ret;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册