]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetSSHSessionAuthAddPrivKeyAuth: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Dec 2022 13:18:16 +0000 (14:18 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 23 Jan 2023 15:32:26 +0000 (16:32 +0100)
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>
src/rpc/virnetsshsession.c

index 08f246be610b2e30bfa5e13d41ba177ca604294c..82cb44a358e68e060696b1b60bbd85fa08422661 100644 (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)))
-        goto error;
+    if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
+        virObjectUnlock(sess);
+        return -1;
+    }
 
-    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