From: Stefan Hajnoczi <stefanha@gmail.com>
To: Saurav Sachidanand <sauravsachidanand@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, laurent@vivier.eu
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] util: Use g_malloc/g_free in envlist.c
Date: Thu, 16 Mar 2017 17:12:14 +0800 [thread overview]
Message-ID: <20170316091214.GC27579@stefanha-x1.localdomain> (raw)
In-Reply-To: <20170305025605.3824-1-sauravsachidanand@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1727 bytes --]
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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
prev parent reply other threads:[~2017-03-16 9:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-05 2:56 [Qemu-devel] [Qemu-trivial] [PATCH v2] util: Use g_malloc/g_free in envlist.c Saurav Sachidanand
2017-03-16 9:12 ` Stefan Hajnoczi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170316091214.GC27579@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=sauravsachidanand@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).