[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH][Outreachy]
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH][Outreachy] |
Date: |
Sat, 5 Mar 2016 19:04:35 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
On 05/03/2016 07:45, Sarah Khan wrote:
> util/envlist.c:This patch replaces malloc with g_malloc
This should be placed in the subject. Please follow the instructions at
http://wiki.qemu.org/Contribute/SubmitAPatch#Submitting_your_Patches to
format the patch correctly.
> - if ((envlist = malloc(sizeof (*envlist))) == NULL)
> + if ((envlist = g_malloc(sizeof (*envlist))) == NULL)
> return (NULL);
g_malloc will never return NULL, so you can remove the if.
> - if ((entry = malloc(sizeof (*entry))) == NULL)
> + if ((entry = g_malloc(sizeof (*entry))) == NULL)
> return (errno);
Likewise.
> if ((entry->ev_var = strdup(env)) == NULL) {
You could also replace strdup with g_strdup...
> - free(entry);
> + g_free(entry);
> return (errno);
> }
> QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link);
> @@ -201,8 +201,8 @@ envlist_unsetenv(envlist_t *envlist, const char *env)
> }
> if (entry != NULL) {
> QLIST_REMOVE(entry, ev_link);
> - free((char *)entry->ev_var);
> - free(entry);
> + g_free((char *)entry->ev_var);
... because here you are replacing its freeing with g_free.
> + g_free(entry);
>
> envlist->el_count--;
> }
> @@ -225,7 +225,7 @@ envlist_to_environ(const envlist_t *envlist, size_t
> *count)
> struct envlist_entry *entry;
> char **env, **penv;
>
> - penv = env = malloc((envlist->el_count + 1) * sizeof (char *));
> + penv = env = g_malloc((envlist->el_count + 1) * sizeof (char *));
> if (env == NULL)
> return (NULL);
This if can be removed.
Note that you have included the patch twice in your message.
Thanks,
Paolo