From patchwork Fri Mar 21 10:12:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 332542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 146BB2C007E for ; Fri, 21 Mar 2014 21:27:46 +1100 (EST) Received: from localhost ([::1]:51867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQwfv-0003Nx-F0 for incoming@patchwork.ozlabs.org; Fri, 21 Mar 2014 06:27:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQwRr-0007UD-1n for qemu-devel@nongnu.org; Fri, 21 Mar 2014 06:13:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQwRi-0007xK-2X for qemu-devel@nongnu.org; Fri, 21 Mar 2014 06:13:10 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:43551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQwRh-0007vt-Q5 for qemu-devel@nongnu.org; Fri, 21 Mar 2014 06:13:01 -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); Fri, 21 Mar 2014 04:12:50 -0600 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Fri, 21 Mar 2014 18:12:43 +0800 Message-Id: <1395396763-26081-33-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1395396763-26081-1-git-send-email-cyliu@suse.com> References: <1395396763-26081-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 v23 32/32] cleanup tmp 'mallocd' member from QemuOptsList 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 Now only qemu_opts_append uses mallocd to indicate free memory. For this function only, we can also let result list's (const char *) members point to input list's members, only if the input list has longer lifetime than result list. In current code, that is true. So, we can remove the 'mallocd' member from QemuOptsList definition to keep code clean. Signed-off-by: Chunyan Liu --- include/qemu/option.h | 5 ----- util/qemu-option.c | 26 ++------------------------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 30533d2..a57e1af 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -63,11 +63,6 @@ typedef struct QemuOptDesc { } QemuOptDesc; struct QemuOptsList { - /* FIXME: Temp used for QEMUOptionParamter->QemuOpts conversion to - * indicate free memory. Will remove after all drivers switch to QemuOpts. - */ - bool mallocd; - const char *name; const char *implied_opt_name; bool merge_lists; /* Merge multiple uses of option into a single list? */ diff --git a/util/qemu-option.c b/util/qemu-option.c index c98f729..752f220 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1054,26 +1054,12 @@ static size_t count_opts_list(QemuOptsList *list) void qemu_opts_free(QemuOptsList *list) { - /* List members point to new malloced space and need to free. - * FIXME: - * Introduced for QEMUOptionParamter->QemuOpts conversion. - * Will remove after all drivers switch to QemuOpts. - */ - if (list && list->mallocd) { - QemuOptDesc *desc = list->desc; - while (desc && desc->name) { - g_free((char *)desc->name); - g_free((char *)desc->help); - g_free((char *)desc->def_value_str); - desc++; - } - } - g_free(list); } /* Realloc dst option list and append options from an option list (list) * to it. dst could be NULL or a malloced list. + * Result dst has shorter lifetime then input list. */ QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list) @@ -1102,23 +1088,15 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, dst->name = NULL; dst->implied_opt_name = NULL; QTAILQ_INIT(&dst->head); - dst->mallocd = true; } dst->desc[num_dst_opts].name = NULL; - /* (const char *) members of result dst are malloced, need free. */ - assert(dst->mallocd); /* append list->desc to dst->desc */ if (list) { desc = list->desc; while (desc && desc->name) { if (find_desc_by_name(dst->desc, desc->name) == NULL) { - dst->desc[num_dst_opts].name = g_strdup(desc->name); - dst->desc[num_dst_opts].type = desc->type; - dst->desc[num_dst_opts].help = g_strdup(desc->help); - dst->desc[num_dst_opts].def_value_str = - g_strdup(desc->def_value_str); - num_dst_opts++; + dst->desc[num_dst_opts++] = *desc; dst->desc[num_dst_opts].name = NULL; } desc++;