提交 66770bc6 编写于 作者: P Peter Krempa

virsh: secret: Refactor cleanup in cmdSecretSetValue

Automatically clean the secret object and get rid of the cleanup label
and 'ret' valiable.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 7e8ed7d7
...@@ -188,18 +188,17 @@ static const vshCmdOptDef opts_secret_set_value[] = { ...@@ -188,18 +188,17 @@ static const vshCmdOptDef opts_secret_set_value[] = {
static bool static bool
cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
{ {
virSecretPtr secret; g_autoptr(virshSecret) secret = NULL;
size_t value_size; size_t value_size;
const char *base64 = NULL; const char *base64 = NULL;
unsigned char *value; unsigned char *value;
int res; int res;
bool ret = false;
if (!(secret = virshCommandOptSecret(ctl, cmd, NULL))) if (!(secret = virshCommandOptSecret(ctl, cmd, NULL)))
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0) if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0)
goto cleanup; return false;
value = g_base64_decode(base64, &value_size); value = g_base64_decode(base64, &value_size);
...@@ -209,14 +208,10 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) ...@@ -209,14 +208,10 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
if (res != 0) { if (res != 0) {
vshError(ctl, "%s", _("Failed to set secret value")); vshError(ctl, "%s", _("Failed to set secret value"));
goto cleanup; return false;
} }
vshPrintExtra(ctl, "%s", _("Secret value set\n")); vshPrintExtra(ctl, "%s", _("Secret value set\n"));
ret = true; return true;
cleanup:
virshSecretFree(secret);
return ret;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册