From patchwork Thu Oct 15 21:06:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7409971 Return-Path: X-Original-To: patchwork-linux-nvdimm@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 071A69F7C9 for ; Thu, 15 Oct 2015 21:12:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2BF0F2069D for ; Thu, 15 Oct 2015 21:12:32 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E513206AF for ; Thu, 15 Oct 2015 21:12:31 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 42288605A5; Thu, 15 Oct 2015 14:12:31 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id 01460605A6 for ; Thu, 15 Oct 2015 14:12:29 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 15 Oct 2015 14:12:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,687,1437462000"; d="scan'208";a="827735496" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.39]) by orsmga002.jf.intel.com with ESMTP; 15 Oct 2015 14:12:08 -0700 Subject: [PATCH 08/11] ndctl: fix leak in check_btt_create From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 15 Oct 2015 17:06:26 -0400 Message-ID: <20151015210626.22046.26821.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20151015210544.22046.31483.stgit@dwillia2-desk3.jf.intel.com> References: <20151015210544.22046.31483.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, 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 Free @buf on all exit paths. Signed-off-by: Dan Williams --- lib/test-libndctl.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/test-libndctl.c b/lib/test-libndctl.c index 93ceb358a301..423dab5c95c2 100644 --- a/lib/test-libndctl.c +++ b/lib/test-libndctl.c @@ -538,7 +538,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace btt = get_idle_btt(region); if (!btt) - return -ENXIO; + goto err; devname = ndctl_btt_get_devname(btt); ndctl_btt_set_uuid(btt, btt_s->uuid); @@ -551,14 +551,14 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace namespace->ro ? "failure" : "success", ndctl_region_get_devname(region), namespace->ro ? "only" : "write"); - return -ENXIO; + goto err; } if (btt_seed == ndctl_region_get_btt_seed(region) && btt == btt_seed) { fprintf(stderr, "%s: failed to advance btt seed\n", ndctl_region_get_devname(region)); - return -ENXIO; + goto err; } /* check new seed creation for BLK regions */ @@ -567,7 +567,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace && ndns == ns_seed) { fprintf(stderr, "%s: failed to advance namespace seed\n", ndctl_region_get_devname(region)); - return -ENXIO; + goto err; } } @@ -577,7 +577,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace fprintf(stderr, "%s: failed to enable after setting rw\n", devname); ndctl_region_set_ro(region, 1); - return -ENXIO; + goto err; } sprintf(bdevpath, "/dev/%s", ndctl_btt_get_block_device(btt)); @@ -616,7 +616,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace close(fd); if (rc) - return rc; + break; rc = ndctl_btt_delete(btt); if (rc) @@ -624,6 +624,9 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace } free(buf); return rc; + err: + free(buf); + return -ENXIO; } static int configure_namespace(struct ndctl_region *region,