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 v3] util: Use g_malloc/g_free in envlist.c
Date: Mon, 20 Mar 2017 14:31:25 +0000 [thread overview]
Message-ID: <20170320143125.GB17887@stefanha-x1.localdomain> (raw)
In-Reply-To: <20170319162715.2260-1-sauravsachidanand@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]
On Sun, Mar 19, 2017 at 04:27:15PM +0000, Saurav Sachidanand wrote:
> @@ -48,10 +46,10 @@ envlist_free(envlist_t *envlist)
> entry = envlist->el_entries.lh_first;
> QLIST_REMOVE(entry, ev_link);
>
> - free((char *)entry->ev_var);
> + g_free(entry->ev_var);
You need to keep the const casts to silence the compiler. Here, ...
> @@ -155,18 +152,14 @@ envlist_setenv(envlist_t *envlist, const char *env)
>
> if (entry != NULL) {
> QLIST_REMOVE(entry, ev_link);
> - free((char *)entry->ev_var);
> + g_free(entry->ev_var);
here, ...
> @@ -201,8 +194,8 @@ envlist_unsetenv(envlist_t *envlist, const char *env)
> }
> if (entry != NULL) {
> QLIST_REMOVE(entry, ev_link);
> - free((char *)entry->ev_var);
> + g_free(entry->ev_var);
and here.
The problem is that const char * is not supposed to be freed. The type
would need to be non-const. Most of the code does treat the string as
const, so it's nice to have it except for the final free().
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
prev parent reply other threads:[~2017-03-20 14:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-19 16:27 [Qemu-devel] [Qemu-trivial] [PATCH v3] util: Use g_malloc/g_free in envlist.c Saurav Sachidanand
2017-03-19 16:32 ` no-reply
2017-03-20 14:31 ` 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=20170320143125.GB17887@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).