From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 067D728EE; Mon, 22 May 2017 11:15:56 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2017 02:15:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,377,1491289200"; d="scan'208";a="859879247" Received: from dpdk19.sh.intel.com (HELO localhost.localdomain) ([10.239.129.163]) by FMSMGA003.fm.intel.com with ESMTP; 22 May 2017 02:15:54 -0700 From: Tiwei Bie To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Date: Mon, 22 May 2017 17:03:48 +0800 Message-Id: <20170522090349.82175-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170522090349.82175-1-tiwei.bie@intel.com> References: <20170509084707.29949-1-tiwei.bie@intel.com> <20170522090349.82175-1-tiwei.bie@intel.com> Subject: [dpdk-dev] [PATCH v2 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: Mon, 22 May 2017 09:15:57 -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.12.1