On Sun, Jun 03, 2018 at 01:42:01PM +0530, Sukrit Bhatnagar wrote: > Modify code to use VIR_AUTOFREE macro wherever required. > > Signed-off-by: Sukrit Bhatnagar <skrtbht...@gmail.com> > --- > src/util/virauth.c | 60 > +++++++++++++++++++----------------------------------- > 1 file changed, 21 insertions(+), 39 deletions(-) > > diff --git a/src/util/virauth.c b/src/util/virauth.c > index adb093e..089a820 100644 > --- a/src/util/virauth.c > +++ b/src/util/virauth.c > @@ -42,10 +42,9 @@ int > virAuthGetConfigFilePathURI(virURIPtr uri, > char **path) > { > - int ret = -1; > size_t i; > const char *authenv = virGetEnvBlockSUID("LIBVIRT_AUTH_FILE"); > - char *userdir = NULL; > + VIR_AUTOFREE(char *) userdir = NULL; > > *path = NULL; > > @@ -54,7 +53,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, > if (authenv) { > VIR_DEBUG("Using path from env '%s'", authenv); > if (VIR_STRDUP(*path, authenv) < 0) > - goto cleanup; > + return -1; > return 0; > } > > @@ -64,41 +63,38 @@ virAuthGetConfigFilePathURI(virURIPtr uri, > uri->params[i].value) { > VIR_DEBUG("Using path from URI '%s'", uri->params[i].value); > if (VIR_STRDUP(*path, uri->params[i].value) < 0) > - goto cleanup; > + return -1; > return 0; > } > } > } > > if (!(userdir = virGetUserConfigDirectory())) > - goto cleanup; > + return -1; > > if (virAsprintf(path, "%s/auth.conf", userdir) < 0) > - goto cleanup; > + return -1; > > VIR_DEBUG("Checking for readability of '%s'", *path); > - if (access(*path, R_OK) == 0) > - goto done; > + if (access(*path, R_OK) == 0) { > + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); > + return 0; > + }
This should be left untouched (minus the @ret variable), it's actually better not to copy the VIR_DEBUG message on multiple places. The same goes for the hunk below... Erik > > VIR_FREE(*path); > > if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) > - goto cleanup; > + return -1; > > VIR_DEBUG("Checking for readability of '%s'", *path); > - if (access(*path, R_OK) == 0) > - goto done; > + if (access(*path, R_OK) == 0) { > + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); > + return 0; > + } > > VIR_FREE(*path); > > - done: > - ret = 0; > - > - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); > - cleanup: > - VIR_FREE(userdir); > - > - return ret; > + return 0; > } > > > @@ -156,7 +152,7 @@ virAuthGetUsernamePath(const char *path, > { > unsigned int ncred; > virConnectCredential cred; > - char *prompt; > + VIR_AUTOFREE(char *) prompt = NULL; > char *ret = NULL; > > if (virAuthGetCredential(servicename, hostname, "username", path, &ret) > < 0) > @@ -193,8 +189,6 @@ virAuthGetUsernamePath(const char *path, > break; > } > > - VIR_FREE(prompt); > - > return cred.result; > } > > @@ -206,18 +200,13 @@ virAuthGetUsername(virConnectPtr conn, > const char *defaultUsername, > const char *hostname) > { > - char *ret; > - char *path; > + VIR_AUTOFREE(char *) path = NULL; > > if (virAuthGetConfigFilePath(conn, &path) < 0) > return NULL; > > - ret = virAuthGetUsernamePath(path, auth, servicename, > + return virAuthGetUsernamePath(path, auth, servicename, > defaultUsername, hostname); > - > - VIR_FREE(path); > - > - return ret; > } > > > @@ -230,7 +219,7 @@ virAuthGetPasswordPath(const char *path, > { > unsigned int ncred; > virConnectCredential cred; > - char *prompt; > + VIR_AUTOFREE(char *) prompt = NULL; > char *ret = NULL; > > if (virAuthGetCredential(servicename, hostname, "password", path, &ret) > < 0) > @@ -264,8 +253,6 @@ virAuthGetPasswordPath(const char *path, > break; > } > > - VIR_FREE(prompt); > - > return cred.result; > } > > @@ -277,15 +264,10 @@ virAuthGetPassword(virConnectPtr conn, > const char *username, > const char *hostname) > { > - char *ret; > - char *path; > + VIR_AUTOFREE(char *) path = NULL; > > if (virAuthGetConfigFilePath(conn, &path) < 0) > return NULL; > > - ret = virAuthGetPasswordPath(path, auth, servicename, username, > hostname); > - > - VIR_FREE(path); > - > - return ret; > + return virAuthGetPasswordPath(path, auth, servicename, username, > hostname); > } > -- > 1.8.3.1 > > -- > libvir-list mailing list > libvir-list@redhat.com > https://www.redhat.com/mailman/listinfo/libvir-list -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list