From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 00A1768A9; Tue, 9 May 2017 10:48:35 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP; 09 May 2017 01:48:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,313,1491289200"; d="scan'208";a="1166602935" Received: from unknown (HELO localhost.localdomain) ([10.239.129.160]) by fmsmga002.fm.intel.com with ESMTP; 09 May 2017 01:48:34 -0700 From: Tiwei Bie To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org Date: Tue, 9 May 2017 08:47:06 +0000 Message-Id: <20170509084707.29949-2-tiwei.bie@intel.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170509084707.29949-1-tiwei.bie@intel.com> References: <20170509084707.29949-1-tiwei.bie@intel.com> Subject: [dpdk-dev] [PATCH 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: Tue, 09 May 2017 08:48:36 -0000 Fixes: 764bf26873b9 ("add FreeBSD support") Cc: stable@dpdk.org Signed-off-by: Tiwei Bie --- 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