Received: from eggs.gnu.org ([2001:4830:134:3::10]:43639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfwSI-00025B-HJ for qemu-devel@nongnu.org; Thu, 01 May 2014 15:15:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WfwSC-0004z4-9t for qemu-devel@nongnu.org; Thu, 01 May 2014 15:15:38 -0400 Received: from mail-yk0-f170.google.com ([209.85.160.170]:50953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfwSC-0004yw-6X for qemu-devel@nongnu.org; Thu, 01 May 2014 15:15:32 -0400 Received: by mail-yk0-f170.google.com with SMTP id 79so3015851ykr.15 for ; Thu, 01 May 2014 12:15:31 -0700 (PDT) Date: Thu, 1 May 2014 16:15:35 -0300 From: Leandro Dorileo Message-ID: <20140501191535.GE29944@dorilex-lnv.MultilaserAP> References: <1398762521-25733-1-git-send-email-cyliu@suse.com> <1398762521-25733-6-git-send-email-cyliu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1398762521-25733-6-git-send-email-cyliu@suse.com> Subject: Re: [Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt->name|str from (const char *) to (char *) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chunyan Liu Cc: qemu-devel@nongnu.org, stefanha@redhat.com On Tue, Apr 29, 2014 at 05:08:14PM +0800, Chunyan Liu wrote: > qemu_opt_del() already assumes that all QemuOpt instances contain > malloc'd name and value; but it had to cast away const because > opts_start_struct() was doing its own thing and using static storage > instead. By using the correct type and malloced strings everywhere, the > usage of this struct becomes clearer. > > Reviewed-by: Eric Blake > Signed-off-by: Chunyan Liu Reviewed-by: Leandro Dorileo > --- > include/qemu/option_int.h | 4 ++-- > qapi/opts-visitor.c | 10 +++++++--- > util/qemu-option.c | 4 ++-- > 3 files changed, 11 insertions(+), 7 deletions(-) > > diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h > index 8212fa4..6432c1a 100644 > --- a/include/qemu/option_int.h > +++ b/include/qemu/option_int.h > @@ -30,8 +30,8 @@ > #include "qemu/error-report.h" > > struct QemuOpt { > - const char *name; > - const char *str; > + char *name; > + char *str; > > const QemuOptDesc *desc; > union { > diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c > index 5d830a2..7a64f4e 100644 > --- a/qapi/opts-visitor.c > +++ b/qapi/opts-visitor.c > @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char *kind, > if (ov->opts_root->id != NULL) { > ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt); > > - ov->fake_id_opt->name = "id"; > - ov->fake_id_opt->str = ov->opts_root->id; > + ov->fake_id_opt->name = g_strdup("id"); > + ov->fake_id_opt->str = g_strdup(ov->opts_root->id); > opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt); > } > } > @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp) > } > g_hash_table_destroy(ov->unprocessed_opts); > ov->unprocessed_opts = NULL; > - g_free(ov->fake_id_opt); > + if (ov->fake_id_opt) { > + g_free(ov->fake_id_opt->name); > + g_free(ov->fake_id_opt->str); > + g_free(ov->fake_id_opt); > + } > ov->fake_id_opt = NULL; > } > > diff --git a/util/qemu-option.c b/util/qemu-option.c > index 2be6995..69cdf3f 100644 > --- a/util/qemu-option.c > +++ b/util/qemu-option.c > @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) > static void qemu_opt_del(QemuOpt *opt) > { > QTAILQ_REMOVE(&opt->opts->head, opt, next); > - g_free((/* !const */ char*)opt->name); > - g_free((/* !const */ char*)opt->str); > + g_free(opt->name); > + g_free(opt->str); > g_free(opt); > } > > -- > 1.8.4.5 > > -- Leandro Dorileo