From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 251BEA034E; Tue, 22 Feb 2022 19:20:02 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4214D41156; Tue, 22 Feb 2022 19:19:23 +0100 (CET) Received: from out203-205-251-66.mail.qq.com (out203-205-251-66.mail.qq.com [203.205.251.66]) by mails.dpdk.org (Postfix) with ESMTP id E006841203 for ; Tue, 22 Feb 2022 19:19:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1645553958; bh=HkUB0yLfOf9e2Ucfp75NNAQidwzPKAZ8bozh3ctalUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gFqyc37lbXxXwPNsV6BMdWmx2XfwFx4VV74jDMsxBahnRcDY8HVyR1ifOfIbU88mY US00ZymkBdTNSOqFGXX9LeBPFkHLewQ1ayPkTJShF1usILNSWl46rydVLlXN/BvZJE UE5QZDsqdiYg/eUzm0ovS/d9MUjurhMfTkw46BHI= Received: from localhost.localdomain ([111.193.130.237]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 49223207; Wed, 23 Feb 2022 02:18:18 +0800 X-QQ-mid: xmsmtpt1645553954toprs0xa0 Message-ID: X-QQ-XMAILINFO: MMnP0fEUKo/hTdFkx4DHOYP2uHvg+Gxa9vjk6syS2kkgR8kF3ppPl4wklm92pD 2jzpAzVWJgBZP9omb+ezcFyKAF6mCYrl+w70IGciTGBL9gGjd41chDDOo1/cwbX7CgYU59Ln7WFC ucljHJqMeDBxzWlBOjXFSvIFF3j9CPLtKM8pPrqU7pAbrtYshpmE3D8rqGa3K4SJqWANqZj0RE4b 9GszD9FsZU4nkjNELxIgGF5JLMv+D/Na5ubqJOqBPPbXtAAhIgZVIcS9u8ABXn5D53Pw3s0CsMMr skpACiRPFSD8QmS+KHL4tQXv0uqlDCwqPc7sg1DK4vrm3uipzx1sFq6Zl45QtL4aK5xdCvsJGEvk V3hQ22xay7bZa6XRI/r7CpFUzkzQIqpyR3icAB31w4z7YuhqOrgtC/rH/7EtySmtpusEM1KIiC8z sePbY1YuPCJp3UCk9JKw4YXAVNrbLtiDUtPCjjp2D9u6umEZ//BRkfpvPIZ92LtyGpX/s8gTgzPh gPklifScI7BUt2cII+Ee7oZm9IgCqFT/srY3X1fYBvUnh9tFLrsUPc9jwm2bhsYxTd11lrXi5ek/ 7pWOxGjqsLFymfQ+PzAXvUeXHBJTspe5y3cuCT/xetsGChG4ZB9jGZdIC+ldbOQI3+VjYQoYWskt qo+r455tKfYS3UIr0nOTsrRSQXQvemlFvEmbolS9oIJPj6rHsk/enbL3vl5V0v5+2IBeLKDoDuBn PbXHp/9omCAP9z6b5IpzM9BA3Ao/YaL0jieN7lxl7qapQqpR0IESzhMxjZXv36ZFXGlKIcHrjC06 6UjRVPRRHU04kyV5TaFrTkSDVYIrextA6v5Q5IEqYBglplY1ghnuRt1FgkEV0bZsrmlrt+e2D5uD WQIqkVH7z5OnkEanyOeaFMWQQ+Q2vvyg== From: Weiguo Li To: dev@dpdk.org Cc: adypodoman@gmail.com, xiaoyun.li@intel.com, tianfei.zhang@intel.com, bruce.richardson@intel.com, ivan.malov@oktetlabs.ru, jgrajcia@cisco.com, hkalra@marvell.com, ying.a.wang@intel.com, ting.xu@intel.com, simei.su@intel.com, qiming.yang@intel.com, motih@mellanox.com, shreyansh.jain@nxp.com, skoteshwar@marvell.com, stephen@networkplumber.org, kalesh-anakkur.purayil@broadcom.com, somnath.kotur@broadcom.com, declan.doherty@intel.com, gakhil@marvell.com, nicolas.chautru@intel.com Subject: [PATCH 14/20] net/ice: avoid fix memory leaks in register parser Date: Wed, 23 Feb 2022 02:18:12 +0800 X-OQ-MSGID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 1) When 'ice_get_parser_list()' fails and return, 'parser_node' is not released, we can move the parser list action ahead of the memory allocation to avoid this memory leak. 2) In another error handling branch, we release 'parser_node' directly to avoid the memory leak. Fixes: 7615a6895009cb ("net/ice: rework for generic flow enabling") Signed-off-by: Weiguo Li --- drivers/net/ice/ice_generic_flow.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ice/ice_generic_flow.c b/drivers/net/ice/ice_generic_flow.c index 53b1c0b69a..e3df090186 100644 --- a/drivers/net/ice/ice_generic_flow.c +++ b/drivers/net/ice/ice_generic_flow.c @@ -1920,6 +1920,10 @@ ice_register_parser(struct ice_flow_parser *parser, struct ice_flow_parser_node *existing_node; void *temp; + list = ice_get_parser_list(parser, ad); + if (list == NULL) + return -EINVAL; + parser_node = rte_zmalloc("ice_parser", sizeof(*parser_node), 0); if (parser_node == NULL) { PMD_DRV_LOG(ERR, "Failed to allocate memory."); @@ -1927,10 +1931,6 @@ ice_register_parser(struct ice_flow_parser *parser, } parser_node->parser = parser; - list = ice_get_parser_list(parser, ad); - if (list == NULL) - return -EINVAL; - if (ad->devargs.pipe_mode_support) { TAILQ_INSERT_TAIL(list, parser_node, node); } else { @@ -1961,6 +1961,7 @@ ice_register_parser(struct ice_flow_parser *parser, } else if (parser->engine->type == ICE_FLOW_ENGINE_ACL) { TAILQ_INSERT_HEAD(list, parser_node, node); } else { + rte_free(parser_node); return -EINVAL; } } -- 2.25.1