Re: [RFC 3/4] add automatic cleanup support in src/util/virauthconfig.c

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

 



On Wed, May 30, 2018 at 02:30:06AM +0530, Sukrit Bhatnagar wrote:
> Modifiy code to use cleanup macros where required.

s/fiy/fy

>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx>
> ---
>  src/util/virauthconfig.c | 34 ++++++++++++----------------------
>  1 file changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
> index 91c9c0c..66f7f7e 100644
> --- a/src/util/virauthconfig.c
> +++ b/src/util/virauthconfig.c
> @@ -106,10 +106,9 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
>                          const char *credname,
>                          const char **value)
>  {
> -    char *authgroup = NULL;
> -    char *credgroup = NULL;
> +    VIR_AUTOFREE(char *) authgroup = NULL;
> +    VIR_AUTOFREE(char *) credgroup = NULL;
>      const char *authcred;
> -    int ret = -1;
>
>      *value = NULL;
>
> @@ -119,47 +118,38 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
>          hostname = "localhost";
>
>      if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
> -        goto cleanup;
> +        return -1;
>
>      if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
>         VIR_FREE(authgroup);
>         if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0)
> -           goto cleanup;
> +           return -1;
>      }
>
> -    if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
> -        ret = 0;
> -        goto cleanup;
> -    }
> +    if (!virKeyFileHasGroup(auth->keyfile, authgroup))
> +        return 0;
>
>      if (!(authcred = virKeyFileGetValueString(auth->keyfile, authgroup, "credentials"))) {
>          virReportError(VIR_ERR_CONF_SYNTAX,
>                         _("Missing item 'credentials' in group '%s' in '%s'"),
>                         authgroup, auth->path);
> -        goto cleanup;
> +        return -1;
>      }
>
>      if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
> -        goto cleanup;
> +        return -1;
>
>      if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
>          virReportError(VIR_ERR_CONF_SYNTAX,
>                         _("Missing group 'credentials-%s' referenced from group '%s' in '%s'"),
>                         authcred, authgroup, auth->path);
> -        goto cleanup;
> +        return -1;
>      }
>
> -    if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) {
> -        ret = 0;
> -        goto cleanup;
> -    }
> +    if (!virKeyFileHasValue(auth->keyfile, credgroup, credname))
> +        return 0;
>
>      *value = virKeyFileGetValueString(auth->keyfile, credgroup, credname);
>
> -    ret = 0;
> -
> - cleanup:
> -    VIR_FREE(authgroup);
> -    VIR_FREE(credgroup);
> -    return ret;
> +    return 0;
>  }

Looks fine as well.

Erik

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