From fb5949748420ebcc63be53fd11feafd089d3284a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 1 Apr 2019 15:04:54 +0200 Subject: [PATCH] Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor code paths which clear strings on cleanup paths to use the automatic helper. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/libxl/libxl_conf.c | 3 +-- src/qemu/qemu_command.c | 3 +-- src/rpc/virnetlibsshsession.c | 13 ++++--------- src/storage/storage_backend_rbd.c | 3 +-- tools/virsh-secret.c | 3 +-- 5 files changed, 8 insertions(+), 17 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..b9143239b9 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -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; } 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; } -- GitLab