From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail01.arraynetworks.com.cn (mail.arraynetworks.com.cn [124.42.99.121]) by dpdk.org (Postfix) with ESMTP id 609D95320 for ; Mon, 14 Mar 2016 10:08:10 +0100 (CET) Received: from AN.localdomain (10.8.3.129) by mail01.arraynetworks.com.cn (10.3.0.251) with Microsoft SMTP Server id 14.3.123.3; Mon, 14 Mar 2016 17:08:01 +0800 From: Jiangu Zhao To: CC: Date: Mon, 14 Mar 2016 09:02:04 +0000 Message-ID: <1457946124-17767-1-git-send-email-zhaojg@arraynetworks.com.cn> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.8.3.129] Subject: [dpdk-dev] [PATCH] i40e: fix using memory after free issue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2016 09:08:11 -0000 The old code still uses entry in the next loop of LIST_FOREACH after free() in i40e_res_pool_destroy(). Change to a safe way to free entry, which is similar with LIST_FOREACH_SAFE in FreeBSD. Signed-off-by: Jiangu Zhao --- drivers/net/i40e/i40e_ethdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index 2f676f6..5af2128 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -3317,17 +3317,21 @@ i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base, static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool) { - struct pool_entry *entry; + struct pool_entry *entry, *next_entry; if (pool == NULL) return; - LIST_FOREACH(entry, &pool->alloc_list, next) { + for (entry = LIST_FIRST(&pool->alloc_list); + entry && (next_entry = LIST_NEXT(entry, next), 1); + entry = next_entry) { LIST_REMOVE(entry, next); rte_free(entry); } - LIST_FOREACH(entry, &pool->free_list, next) { + for (entry = LIST_FIRST(&pool->free_list); + entry && (next_entry = LIST_NEXT(entry, next), 1); + entry = next_entry) { LIST_REMOVE(entry, next); rte_free(entry); } -- 1.8.3.1