[PATCH 03/10] Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactor code paths which clear strings on cleanup paths to use the
automatic helper.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libxl/libxl_conf.c            |  3 +--
 src/qemu/qemu_command.c           |  3 +--
 src/rpc/virnetlibsshsession.c     | 10 +++-------
 src/storage/storage_backend_rbd.c |  3 +--
 tools/virsh-secret.c              |  3 +--
 5 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e55a9fe22e..0c7a5f3dd5 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -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;
 }
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f81d20e5f7..98d67dab2c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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:
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index e851e40d48..832d4fd87d 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -605,7 +605,7 @@ static int
 virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
                                  virNetLibsshAuthMethodPtr priv)
 {
-    char *password = NULL;
+    VIR_AUTODISPOSE_STR password = NULL;
     const char *errmsg;
     int ret = -1;

@@ -657,10 +657,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
     virReportError(VIR_ERR_AUTH_FAILED,
                    _("authentication failed: %s"), errmsg);

-    return ret;
-
  cleanup:
-    VIR_DISPOSE_STRING(password);
     return ret;
 }

@@ -1052,7 +1049,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
 {
     int ret;
     virNetLibsshAuthMethodPtr auth;
-    char *pass = NULL;
+    VIR_AUTODISPOSE_STR pass = NULL;
     char *file = NULL;

     if (!keyfile) {
@@ -1076,7 +1073,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 +1085,6 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
     return ret;

  error:
-    VIR_DISPOSE_STRING(pass);
     VIR_FREE(file);
     goto cleanup;
 }
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 61ebb9b541..29f6a5de60 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -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);
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 9227fd064c..b9fc5ededf 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -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;
 }
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux