From patchwork Tue Jan 26 21:30:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 8127651 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 13EB9BEEE5 for ; Tue, 26 Jan 2016 21:33:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 380072026D for ; Tue, 26 Jan 2016 21:33:55 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C60FE20225 for ; Tue, 26 Jan 2016 21:33:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOBCi-0004bR-Ij; Tue, 26 Jan 2016 21:31:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOBCh-0004ay-79 for xen-devel@lists.xenproject.org; Tue, 26 Jan 2016 21:31:11 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 5A/3F-02940-E95E7A65; Tue, 26 Jan 2016 21:31:10 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1453843868!1086523!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15567 invoked from network); 26 Jan 2016 21:31:09 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-9.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jan 2016 21:31:09 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u0QLV5CH001245 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2016 21:31:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u0QLV4VV001541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 26 Jan 2016 21:31:05 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u0QLV3W4025705; Tue, 26 Jan 2016 21:31:04 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Jan 2016 13:31:02 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 80C896A01C8; Tue, 26 Jan 2016 16:31:01 -0500 (EST) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ian.campbell@citrix.com, wei.liu2@citrix.com, Ian.Jackson@eu.citrix.com Date: Tue, 26 Jan 2016 16:30:57 -0500 Message-Id: <1453843860-29591-2-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1453843860-29591-1-git-send-email-konrad.wilk@oracle.com> References: <1453843860-29591-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH 1/4] libxl: Use libxl_strdup instead of strdup on libxl_version_info X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The change is simple replace of raw strdup with a libxl variant. The benefit of that is the libxl variant has the extra behaviour of abort-on-alloc-fail - and will improve error handling. libxl_version_info is a bit odd - it is a public function and as libxl.h mentions - the callers of libxl_ public function needs to call the appropiate _dispose() function. "However libxl_get_version_info() is special and returns a cached result from the ctx which cannot and should not be freed (as evidenced by it returning a const struct). This data is freed in libxl_ctx_free() by calling libxl_version_info_dispose(). This is why none of the callers remember to free -- they shouldn't be doing so." (Ian Campbell) So the patch makes sure to use the NOGC. Suggested-by: Wei Liu Signed-off-by: Konrad Rzeszutek Wilk Acked-by: Wei Liu --- tools/libxl/libxl.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 2bde0f5..548e2e2 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5258,6 +5258,7 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) { + GC_INIT(ctx); union { xen_extraversion_t xen_extra; xen_compile_info_t xen_cc; @@ -5270,26 +5271,26 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) libxl_version_info *info = &ctx->version_info; if (info->xen_version_extra != NULL) - return info; + goto out; xen_version = xc_version(ctx->xch, XENVER_version, NULL); info->xen_version_major = xen_version >> 16; info->xen_version_minor = xen_version & 0xFF; xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); - info->xen_version_extra = strdup(u.xen_extra); + info->xen_version_extra = libxl__strdup(NOGC, u.xen_extra); xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc); - info->compiler = strdup(u.xen_cc.compiler); - info->compile_by = strdup(u.xen_cc.compile_by); - info->compile_domain = strdup(u.xen_cc.compile_domain); - info->compile_date = strdup(u.xen_cc.compile_date); + info->compiler = libxl__strdup(NOGC, u.xen_cc.compiler); + info->compile_by = libxl__strdup(NOGC, u.xen_cc.compile_by); + info->compile_domain = libxl__strdup(NOGC, u.xen_cc.compile_domain); + info->compile_date = libxl__strdup(NOGC, u.xen_cc.compile_date); xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps); - info->capabilities = strdup(u.xen_caps); + info->capabilities = libxl__strdup(NOGC, u.xen_caps); xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset); - info->changeset = strdup(u.xen_chgset); + info->changeset = libxl__strdup(NOGC, u.xen_chgset); xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms); info->virt_start = u.p_parms.virt_start; @@ -5297,8 +5298,10 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL); xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline); - info->commandline = strdup(u.xen_commandline); + info->commandline = libxl__strdup(NOGC, u.xen_commandline); + out: + GC_FREE; return info; }