From patchwork Thu Apr 10 17:54:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 338352 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C0CF31400A8 for ; Fri, 11 Apr 2014 15:55:56 +1000 (EST) Received: from localhost ([::1]:55901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYURO-0005c3-Tz for incoming@patchwork.ozlabs.org; Fri, 11 Apr 2014 01:55:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYUQX-0005Ov-UC for qemu-devel@nongnu.org; Fri, 11 Apr 2014 01:55:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYUQQ-0004VP-Cr for qemu-devel@nongnu.org; Fri, 11 Apr 2014 01:55:01 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:45690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYUQQ-0004Ue-7m for qemu-devel@nongnu.org; Fri, 11 Apr 2014 01:54:54 -0400 Received: from linux-cyliu.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (NOT encrypted); Thu, 10 Apr 2014 23:54:43 -0600 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Fri, 11 Apr 2014 01:54:00 +0800 Message-Id: <1397152467-17186-5-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1397152467-17186-1-git-send-email-cyliu@suse.com> References: <1397152467-17186-1-git-send-email-cyliu@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.26 Cc: l@dorileo.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v25 04/31] QemuOpts: change opt->name|str from (const char *) to (char *) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: Leandro Dorileo Signed-off-by: Chunyan Liu Reviewed-by: Eric Blake --- 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 84f0d5c..065ffb8 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); }