From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 440AA7CDF; Sun, 4 Jun 2017 08:06:01 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 03 Jun 2017 23:06:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,294,1493708400"; d="scan'208";a="110144391" Received: from dpdk19.sh.intel.com (HELO localhost.localdomain) ([10.239.129.166]) by fmsmga005.fm.intel.com with ESMTP; 03 Jun 2017 23:05:59 -0700 From: Tiwei Bie To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Date: Sun, 4 Jun 2017 13:53:23 +0800 Message-Id: <20170604055324.40506-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170604055324.40506-1-tiwei.bie@intel.com> References: <20170522090349.82175-1-tiwei.bie@intel.com> <20170604055324.40506-1-tiwei.bie@intel.com> Subject: [dpdk-dev] [PATCH v3 1/2] contigmem: free the allocated memory when error occurs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Jun 2017 06:06:02 -0000 Fixes: 764bf26873b9 ("add FreeBSD support") Cc: stable@dpdk.org Signed-off-by: Tiwei Bie Acked-by: Bruce Richardson --- lib/librte_eal/bsdapp/contigmem/contigmem.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/bsdapp/contigmem/contigmem.c b/lib/librte_eal/bsdapp/contigmem/contigmem.c index da971debe..03e3e8def 100644 --- a/lib/librte_eal/bsdapp/contigmem/contigmem.c +++ b/lib/librte_eal/bsdapp/contigmem/contigmem.c @@ -123,19 +123,21 @@ static int contigmem_load() { char index_string[8], description[32]; - int i; + int i, error = 0; if (contigmem_num_buffers > RTE_CONTIGMEM_MAX_NUM_BUFS) { printf("%d buffers requested is greater than %d allowed\n", contigmem_num_buffers, RTE_CONTIGMEM_MAX_NUM_BUFS); - return EINVAL; + error = EINVAL; + goto error; } if (contigmem_buffer_size < PAGE_SIZE || (contigmem_buffer_size & (contigmem_buffer_size - 1)) != 0) { printf("buffer size 0x%lx is not greater than PAGE_SIZE and " "power of two\n", contigmem_buffer_size); - return EINVAL; + error = EINVAL; + goto error; } for (i = 0; i < contigmem_num_buffers; i++) { @@ -145,7 +147,8 @@ contigmem_load() if (contigmem_buffers[i] == NULL) { printf("contigmalloc failed for buffer %d\n", i); - return ENOMEM; + error = ENOMEM; + goto error; } printf("%2u: virt=%p phys=%p\n", i, contigmem_buffers[i], @@ -165,6 +168,14 @@ contigmem_load() GID_WHEEL, 0600, "contigmem"); return 0; + +error: + for (i = 0; i < contigmem_num_buffers; i++) + if (contigmem_buffers[i] != NULL) + contigfree(contigmem_buffers[i], contigmem_buffer_size, + M_CONTIGMEM); + + return error; } static int -- 2.13.0