qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] util: Use g_malloc/g_free in


From: Stefan Hajnoczi
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] util: Use g_malloc/g_free in envlist.c
Date: Thu, 16 Mar 2017 17:12:14 +0800
User-agent: Mutt/1.7.1 (2016-10-04)

On Sun, Mar 05, 2017 at 02:56:05AM +0000, Saurav Sachidanand wrote:
> diff --git a/util/envlist.c b/util/envlist.c
> index e86857e70a..a42eefa5fe 100644
> --- a/util/envlist.c
> +++ b/util/envlist.c
> @@ -17,16 +17,14 @@ static int envlist_parse(envlist_t *envlist,
>      const char *env, int (*)(envlist_t *, const char *));
> 
>  /*
> - * Allocates new envlist and returns pointer to that or
> - * NULL in case of error.
> + * Allocates new envlist and returns pointer to it.
>   */
>  envlist_t *
>  envlist_create(void)
>  {
>       envlist_t *envlist;
> 
> -     if ((envlist = malloc(sizeof (*envlist))) == NULL)
> -             return (NULL);
> +  envlist = g_malloc(sizeof(*envlist));

Please use tabs to indent in this file.  Normally QEMU coding style uses
4-space indentation but this file contains old code and it's easiest to
leave it undisturbed.

> 
>       QLIST_INIT(&envlist->el_entries);
>       envlist->el_count = 0;
> @@ -49,9 +47,9 @@ envlist_free(envlist_t *envlist)
>               QLIST_REMOVE(entry, ev_link);
> 
>               free((char *)entry->ev_var);
> -             free(entry);
> +    g_free(entry);
>       }
> -     free(envlist);
> +  g_free(envlist);
>  }
> 
>  /*
> @@ -156,15 +154,15 @@ envlist_setenv(envlist_t *envlist, const char *env)
>       if (entry != NULL) {
>               QLIST_REMOVE(entry, ev_link);
>               free((char *)entry->ev_var);
> -             free(entry);
> +    g_free(entry);
>       } else {
>               envlist->el_count++;
>       }
> 
> -     if ((entry = malloc(sizeof (*entry))) == NULL)
> -             return (errno);
> -     if ((entry->ev_var = strdup(env)) == NULL) {
> -             free(entry);
> +  entry = g_malloc(sizeof(*entry));
> +  entry->ev_var = strdup(env);

Could this be converted to g_strdup() in a separate patch?

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]