From patchwork Wed Feb 10 16:56:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8273291 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B38FD9F3CD for ; Wed, 10 Feb 2016 16:59:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E49B9203B1 for ; Wed, 10 Feb 2016 16:59:19 +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 132A7203A4 for ; Wed, 10 Feb 2016 16:59:19 +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 1aTY45-0005fq-3B; Wed, 10 Feb 2016 16:56:29 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aTY43-0005fF-L0 for xen-devel@lists.xen.org; Wed, 10 Feb 2016 16:56:27 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 09/E5-31122-ABB6BB65; Wed, 10 Feb 2016 16:56:26 +0000 X-Env-Sender: prvs=841e7c5e8=Ian.Campbell@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1455123384!15054528!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32232 invoked from network); 10 Feb 2016 16:56:26 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 10 Feb 2016 16:56:26 -0000 X-IronPort-AV: E=Sophos;i="5.22,426,1449532800"; d="scan'208";a="337327834" From: Ian Campbell To: Daniel De Graaf , , , Date: Wed, 10 Feb 2016 16:56:22 +0000 Message-ID: <1455123382-25942-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Campbell Subject: [Xen-devel] [PATCH] init-xenstore-domain: cleanup all resources on a single exit path 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: , 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 Previously xs_fd would be left open, which is CID 1055993 (previously partially fixed by 3bca826aae5eb). Instead arrange for both success and error cases to cleanup everything on a single exit path instead of doing partial cleanup on the success path a few operations higher up. Signed-off-by: Ian Campbell Acked-by: Wei Liu --- tools/helpers/init-xenstore-domain.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index 5c5af2d..909542b 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -172,9 +172,6 @@ static int build(xc_interface *xch) goto err; } - xc_dom_release(dom); - dom = NULL; - rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC); if ( rv ) { @@ -188,14 +185,18 @@ static int build(xc_interface *xch) goto err; } - return 0; + rv = 0; err: if ( dom ) xc_dom_release(dom); - if ( domid != ~0 ) + if ( xs_fd >= 0 ) + close(xs_fd); + + /* if we failed then destroy the domain */ + if ( rv && domid != ~0 ) xc_domain_destroy(xch, domid); - close(xs_fd); + return rv; }