From patchwork Tue Apr 29 09:10:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 343700 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 30115140099 for ; Tue, 29 Apr 2014 19:12:41 +1000 (EST) Received: from localhost ([::1]:47946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wf45e-0001sY-W4 for incoming@patchwork.ozlabs.org; Tue, 29 Apr 2014 05:12:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wf44r-00009D-Qf for qemu-devel@nongnu.org; Tue, 29 Apr 2014 05:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wf44l-0003Oq-Cj for qemu-devel@nongnu.org; Tue, 29 Apr 2014 05:11:49 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:47322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wf44l-0003OV-3w for qemu-devel@nongnu.org; Tue, 29 Apr 2014 05:11:43 -0400 Received: from linux-tt8j.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (NOT encrypted); Tue, 29 Apr 2014 03:11:28 -0600 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Tue, 29 Apr 2014 17:10:29 +0800 Message-Id: <1398762656-26079-6-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1398762656-26079-1-git-send-email-cyliu@suse.com> References: <1398762656-26079-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: stefanha@redhat.com Subject: [Qemu-devel] [PATCH V26 05/32] 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: Eric Blake Signed-off-by: Chunyan Liu --- 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); }