提交 fb594974 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 a9b3afab
...@@ -980,7 +980,7 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr) ...@@ -980,7 +980,7 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr)
{ {
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
uint8_t *secret = NULL; uint8_t *secret = NULL;
char *base64secret = NULL; VIR_AUTODISPOSE_STR base64secret = NULL;
size_t secretlen = 0; size_t secretlen = 0;
char *username = NULL; char *username = NULL;
int ret = -1; int ret = -1;
...@@ -1008,7 +1008,6 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr) ...@@ -1008,7 +1008,6 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr)
cleanup: cleanup:
VIR_DISPOSE_N(secret, secretlen); VIR_DISPOSE_N(secret, secretlen);
VIR_DISPOSE_STRING(base64secret);
virObjectUnref(conn); virObjectUnref(conn);
return ret; return ret;
} }
......
...@@ -842,7 +842,7 @@ static int ...@@ -842,7 +842,7 @@ static int
qemuBuildRBDSecinfoURI(virBufferPtr buf, qemuBuildRBDSecinfoURI(virBufferPtr buf,
qemuDomainSecretInfoPtr secinfo) qemuDomainSecretInfoPtr secinfo)
{ {
char *base64secret = NULL; VIR_AUTODISPOSE_STR base64secret = NULL;
if (!secinfo) { if (!secinfo) {
virBufferAddLit(buf, ":auth_supported=none"); virBufferAddLit(buf, ":auth_supported=none");
...@@ -858,7 +858,6 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf, ...@@ -858,7 +858,6 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf,
virBufferEscape(buf, '\\', ":", virBufferEscape(buf, '\\', ":",
":key=%s:auth_supported=cephx\\;none", ":key=%s:auth_supported=cephx\\;none",
base64secret); base64secret);
VIR_DISPOSE_STRING(base64secret);
break; break;
case VIR_DOMAIN_SECRET_INFO_TYPE_AES: case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
......
...@@ -605,7 +605,6 @@ static int ...@@ -605,7 +605,6 @@ static int
virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
virNetLibsshAuthMethodPtr priv) virNetLibsshAuthMethodPtr priv)
{ {
char *password = NULL;
const char *errmsg; const char *errmsg;
int ret = -1; int ret = -1;
...@@ -631,6 +630,8 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -631,6 +630,8 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
/* Try the authenticating the set amount of times. The server breaks the /* Try the authenticating the set amount of times. The server breaks the
* connection if maximum number of bad auth tries is exceeded */ * connection if maximum number of bad auth tries is exceeded */
while (true) { while (true) {
VIR_AUTODISPOSE_STR password = NULL;
if (!(password = virAuthGetPasswordPath(sess->authPath, sess->cred, if (!(password = virAuthGetPasswordPath(sess->authPath, sess->cred,
"ssh", sess->username, "ssh", sess->username,
sess->hostname))) { sess->hostname))) {
...@@ -645,8 +646,6 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -645,8 +646,6 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
goto cleanup; goto cleanup;
} }
VIR_DISPOSE_STRING(password);
if (ret != SSH_AUTH_DENIED) if (ret != SSH_AUTH_DENIED)
break; break;
} }
...@@ -657,10 +656,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -657,10 +656,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
virReportError(VIR_ERR_AUTH_FAILED, virReportError(VIR_ERR_AUTH_FAILED,
_("authentication failed: %s"), errmsg); _("authentication failed: %s"), errmsg);
return ret;
cleanup: cleanup:
VIR_DISPOSE_STRING(password);
return ret; return ret;
} }
...@@ -1052,7 +1048,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess, ...@@ -1052,7 +1048,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
{ {
int ret; int ret;
virNetLibsshAuthMethodPtr auth; virNetLibsshAuthMethodPtr auth;
char *pass = NULL; VIR_AUTODISPOSE_STR pass = NULL;
char *file = NULL; char *file = NULL;
if (!keyfile) { if (!keyfile) {
...@@ -1076,7 +1072,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess, ...@@ -1076,7 +1072,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
goto error; goto error;
} }
auth->password = pass; VIR_STEAL_PTR(auth->password, pass);
auth->filename = file; auth->filename = file;
auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY; auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY;
auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY; auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY;
...@@ -1088,7 +1084,6 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess, ...@@ -1088,7 +1084,6 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
return ret; return ret;
error: error:
VIR_DISPOSE_STRING(pass);
VIR_FREE(file); VIR_FREE(file);
goto cleanup; goto cleanup;
} }
......
...@@ -209,7 +209,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -209,7 +209,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
virStorageAuthDefPtr authdef = source->auth; virStorageAuthDefPtr authdef = source->auth;
unsigned char *secret_value = NULL; unsigned char *secret_value = NULL;
size_t secret_value_size = 0; size_t secret_value_size = 0;
char *rados_key = NULL; VIR_AUTODISPOSE_STR rados_key = NULL;
virBuffer mon_host = VIR_BUFFER_INITIALIZER; virBuffer mon_host = VIR_BUFFER_INITIALIZER;
size_t i; size_t i;
const char *client_mount_timeout = "30"; const char *client_mount_timeout = "30";
...@@ -343,7 +343,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -343,7 +343,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
cleanup: cleanup:
VIR_DISPOSE_N(secret_value, secret_value_size); VIR_DISPOSE_N(secret_value, secret_value_size);
VIR_DISPOSE_STRING(rados_key);
virObjectUnref(conn); virObjectUnref(conn);
virBufferFreeAndReset(&mon_host); virBufferFreeAndReset(&mon_host);
......
...@@ -253,7 +253,7 @@ static bool ...@@ -253,7 +253,7 @@ static bool
cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
{ {
virSecretPtr secret; virSecretPtr secret;
char *base64 = NULL; VIR_AUTODISPOSE_STR base64 = NULL;
unsigned char *value; unsigned char *value;
size_t value_size; size_t value_size;
bool ret = false; bool ret = false;
...@@ -274,7 +274,6 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) ...@@ -274,7 +274,6 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_DISPOSE_N(value, value_size); VIR_DISPOSE_N(value, value_size);
VIR_DISPOSE_STRING(base64);
virSecretFree(secret); virSecretFree(secret);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册