[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [PATCH v3] util: Use g_malloc/g_free in envlist.c
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-trivial] [PATCH v3] util: Use g_malloc/g_free in envlist.c |
Date: |
Mon, 20 Mar 2017 14:31:25 +0000 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
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().
signature.asc
Description: PGP signature