]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetLibsshSessionAuthAddPrivKeyAuth: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Tue, 2 Feb 2021 15:00:28 +0000 (16:00 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 12:07:12 +0000 (13:07 +0100)
Shuffle the code around to remove the need for temporary variables and
labels for cleaning them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/rpc/virnetlibsshsession.c

index ed697c7ce417f2f2cd10d3a5575287be000ab996..9671a0f98dc900159210f452b79433eae8a94a29 100644 (file)
@@ -1013,10 +1013,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
                                       const char *keyfile,
                                       const char *password)
 {
-    int ret;
     virNetLibsshAuthMethodPtr auth;
-    VIR_AUTODISPOSE_STR pass = NULL;
-    char *file = NULL;
 
     if (!keyfile) {
         virReportError(VIR_ERR_LIBSSH, "%s",
@@ -1026,28 +1023,18 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
 
     virObjectLock(sess);
 
-    file = g_strdup(keyfile);
-    pass = g_strdup(password);
-
     if (!(auth = virNetLibsshSessionAuthMethodNew(sess))) {
-        ret = -1;
-        goto error;
+        virObjectUnlock(sess);
+        return -1;
     }
 
-    auth->password = g_steal_pointer(&pass);
-    auth->filename = file;
+    auth->password = g_strdup(password);
+    auth->filename = g_strdup(keyfile);
     auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY;
     auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY;
 
-    ret = 0;
-
- cleanup:
     virObjectUnlock(sess);
-    return ret;
-
- error:
-    VIR_FREE(file);
-    goto cleanup;
+    return 0;
 }
 
 int