]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible
authorPeter Krempa <pkrempa@redhat.com>
Mon, 1 Apr 2019 13:04:54 +0000 (15:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Apr 2019 09:58:10 +0000 (11:58 +0200)
Refactor code paths which clear strings on cleanup paths to use the
automatic helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libxl/libxl_conf.c
src/qemu/qemu_command.c
src/rpc/virnetlibsshsession.c
src/storage/storage_backend_rbd.c
tools/virsh-secret.c

index e55a9fe22eda36bb96fa17ba942a877d97a9c4cc..0c7a5f3dd57eb478cccee823796f2d88f00319fe 100644 (file)
@@ -980,7 +980,7 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr)
 {
     virConnectPtr conn = NULL;
     uint8_t *secret = NULL;
-    char *base64secret = NULL;
+    VIR_AUTODISPOSE_STR base64secret = NULL;
     size_t secretlen = 0;
     char *username = NULL;
     int ret = -1;
@@ -1008,7 +1008,6 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr)
 
  cleanup:
     VIR_DISPOSE_N(secret, secretlen);
-    VIR_DISPOSE_STRING(base64secret);
     virObjectUnref(conn);
     return ret;
 }
index f81d20e5f71892e2c0ad6835e44bdb2d05a09786..98d67dab2cd9bae430ec7372770f62f7d7c9eef9 100644 (file)
@@ -842,7 +842,7 @@ static int
 qemuBuildRBDSecinfoURI(virBufferPtr buf,
                        qemuDomainSecretInfoPtr secinfo)
 {
-    char *base64secret = NULL;
+    VIR_AUTODISPOSE_STR base64secret = NULL;
 
     if (!secinfo) {
         virBufferAddLit(buf, ":auth_supported=none");
@@ -858,7 +858,6 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf,
         virBufferEscape(buf, '\\', ":",
                         ":key=%s:auth_supported=cephx\\;none",
                         base64secret);
-        VIR_DISPOSE_STRING(base64secret);
         break;
 
     case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
index e851e40d48ba48a24bbb18e4a87e155fd15d1458..b9143239b9b9c7d9ebafafec5fee29950288356e 100644 (file)
@@ -605,7 +605,6 @@ static int
 virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
                                  virNetLibsshAuthMethodPtr priv)
 {
-    char *password = NULL;
     const char *errmsg;
     int ret = -1;
 
@@ -631,6 +630,8 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
         /* Try the authenticating the set amount of times. The server breaks the
          * connection if maximum number of bad auth tries is exceeded */
         while (true) {
+            VIR_AUTODISPOSE_STR password = NULL;
+
             if (!(password = virAuthGetPasswordPath(sess->authPath, sess->cred,
                                                     "ssh", sess->username,
                                                     sess->hostname))) {
@@ -645,8 +646,6 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
                 goto cleanup;
             }
 
-            VIR_DISPOSE_STRING(password);
-
             if (ret != SSH_AUTH_DENIED)
                 break;
         }
@@ -657,10 +656,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
     virReportError(VIR_ERR_AUTH_FAILED,
                    _("authentication failed: %s"), errmsg);
 
-    return ret;
-
  cleanup:
-    VIR_DISPOSE_STRING(password);
     return ret;
 }
 
@@ -1052,7 +1048,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
 {
     int ret;
     virNetLibsshAuthMethodPtr auth;
-    char *pass = NULL;
+    VIR_AUTODISPOSE_STR pass = NULL;
     char *file = NULL;
 
     if (!keyfile) {
@@ -1076,7 +1072,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
         goto error;
     }
 
-    auth->password = pass;
+    VIR_STEAL_PTR(auth->password, pass);
     auth->filename = file;
     auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY;
     auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY;
@@ -1088,7 +1084,6 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
     return ret;
 
  error:
-    VIR_DISPOSE_STRING(pass);
     VIR_FREE(file);
     goto cleanup;
 }
index 61ebb9b541230f8b49e6c792ed2a14bbf512a5ff..29f6a5de6047c836b54d217bb9fe81a8ad1dd82f 100644 (file)
@@ -209,7 +209,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
     virStorageAuthDefPtr authdef = source->auth;
     unsigned char *secret_value = NULL;
     size_t secret_value_size = 0;
-    char *rados_key = NULL;
+    VIR_AUTODISPOSE_STR rados_key = NULL;
     virBuffer mon_host = VIR_BUFFER_INITIALIZER;
     size_t i;
     const char *client_mount_timeout = "30";
@@ -343,7 +343,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
 
  cleanup:
     VIR_DISPOSE_N(secret_value, secret_value_size);
-    VIR_DISPOSE_STRING(rados_key);
 
     virObjectUnref(conn);
     virBufferFreeAndReset(&mon_host);
index 9227fd064c06b577b9157b3166af27a5b570e799..b9fc5ededf9882f9929d3e79ba4e67344a00e7dd 100644 (file)
@@ -253,7 +253,7 @@ static bool
 cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
 {
     virSecretPtr secret;
-    char *base64 = NULL;
+    VIR_AUTODISPOSE_STR base64 = NULL;
     unsigned char *value;
     size_t value_size;
     bool ret = false;
@@ -274,7 +274,6 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_DISPOSE_N(value, value_size);
-    VIR_DISPOSE_STRING(base64);
     virSecretFree(secret);
     return ret;
 }