[PATCH v2 06/27] virNetLibsshSessionAuthAddPrivKeyAuth: Refactor cleanup

Peter Krempa posted 27 patches 5 years ago
[PATCH v2 06/27] virNetLibsshSessionAuthAddPrivKeyAuth: Refactor cleanup
Posted by Peter Krempa 5 years ago
Shuffle the code around to remove the need for temporary variables and
labels for cleaning them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/rpc/virnetlibsshsession.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index ed697c7ce4..9671a0f98d 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -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
-- 
2.29.2

Re: [PATCH v2 06/27] virNetLibsshSessionAuthAddPrivKeyAuth: Refactor cleanup
Posted by Daniel P. Berrangé 5 years ago
On Tue, Feb 02, 2021 at 05:55:43PM +0100, Peter Krempa wrote:
> Shuffle the code around to remove the need for temporary variables and
> labels for cleaning them.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/rpc/virnetlibsshsession.c | 23 +++++------------------
>  1 file changed, 5 insertions(+), 18 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|