Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible

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>
This commit is contained in:
Peter Krempa 2019-04-01 15:04:54 +02:00
parent a9b3afabcd
commit fb59497484
5 changed files with 8 additions and 17 deletions

View 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;
}

View 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:

View 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;
}

View 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);

View 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;
}