virNetSSHSessionAuthAddPrivKeyAuth: Refactor cleanup

With g_strdup not failing we can remove all of the 'error' section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-08 14:18:16 +01:00
parent 7f6b632b73
commit 3267ce58cf

View File

@ -1060,9 +1060,6 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSession *sess,
{
virNetSSHAuthMethod *auth;
char *user = NULL;
char *file = NULL;
if (!username || !keyfile) {
virReportError(VIR_ERR_SSH, "%s",
_("Username and key file path must be provided "
@ -1072,24 +1069,17 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSession *sess,
virObjectLock(sess);
user = g_strdup(username);
file = g_strdup(keyfile);
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
virObjectUnlock(sess);
return -1;
}
if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
goto error;
auth->username = user;
auth->filename = file;
auth->username = g_strdup(username);
auth->filename = g_strdup(keyfile);
auth->method = VIR_NET_SSH_AUTH_PRIVKEY;
virObjectUnlock(sess);
return 0;
error:
VIR_FREE(user);
VIR_FREE(file);
virObjectUnlock(sess);
return -1;
}
int