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 A398B4341C for ; Fri, 1 Dec 2023 11:46:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9786542F97; Fri, 1 Dec 2023 11:46:58 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id A0DD940289; Fri, 1 Dec 2023 11:46:55 +0100 (CET) Received: from dggpemm500008.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4ShV484FrQzMnft; Fri, 1 Dec 2023 18:42:00 +0800 (CST) Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 1 Dec 2023 18:46:53 +0800 From: Yunjian Wang To: CC: , , , , Yunjian Wang , Subject: [PATCH 1/1] net/iavf: fix memoy leak in error path Date: Fri, 1 Dec 2023 18:46:49 +0800 Message-ID: <2be401c77779bdc38c8a79b006665ba623c6e2db.1701426993.git.wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.242.157] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500008.china.huawei.com (7.185.36.136) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org In iavf_security_ctx_create() allocated memory for the 'security_ctx', we should free it when memory malloc for the 'iavf_security_ctx' fails, otherwise it will lead to memory leak. Fixes: 6bc987ecb860 ("net/iavf: support IPsec inline crypto") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang --- drivers/net/iavf/iavf_ipsec_crypto.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/iavf/iavf_ipsec_crypto.c b/drivers/net/iavf/iavf_ipsec_crypto.c index 07a69db540..d6c0180ffd 100644 --- a/drivers/net/iavf/iavf_ipsec_crypto.c +++ b/drivers/net/iavf/iavf_ipsec_crypto.c @@ -1518,8 +1518,11 @@ iavf_security_ctx_create(struct iavf_adapter *adapter) if (adapter->security_ctx == NULL) { adapter->security_ctx = rte_malloc("iavf_security_ctx", sizeof(struct iavf_security_ctx), 0); - if (adapter->security_ctx == NULL) + if (adapter->security_ctx == NULL) { + rte_free(adapter->vf.eth_dev->security_ctx); + adapter->vf.eth_dev->security_ctx = NULL; return -ENOMEM; + } } return 0; -- 2.33.0 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 C97DC436E9 for ; Thu, 14 Dec 2023 02:45:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BFB1242F5B; Thu, 14 Dec 2023 02:45:55 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id C753840283; Thu, 14 Dec 2023 02:45:52 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SrFXZ47dGzvS0T; Thu, 14 Dec 2023 09:45:02 +0800 (CST) Received: from dggpemm500008.china.huawei.com (unknown [7.185.36.136]) by mail.maildlp.com (Postfix) with ESMTPS id 253ED140258; Thu, 14 Dec 2023 09:45:50 +0800 (CST) Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 14 Dec 2023 09:45:49 +0800 From: Yunjian Wang To: CC: , , , , , Yunjian Wang , Subject: [PATCH RESEND] net/iavf: fix memoy leak in error path Date: Thu, 14 Dec 2023 09:45:41 +0800 Message-ID: <2be401c77779bdc38c8a79b006665ba623c6e2db.1701426993.git.wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.242.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500008.china.huawei.com (7.185.36.136) X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Message-ID: <20231214014541.vmbU9qHOspWq3fZH8hmaLdNo2YfgfKKdgfHt3VkOTg0@z> In iavf_security_ctx_create() allocated memory for the 'security_ctx', we should free it when memory malloc for the 'iavf_security_ctx' fails, otherwise it will lead to memory leak. Fixes: 6bc987ecb860 ("net/iavf: support IPsec inline crypto") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang --- drivers/net/iavf/iavf_ipsec_crypto.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/iavf/iavf_ipsec_crypto.c b/drivers/net/iavf/iavf_ipsec_crypto.c index 07a69db540..d6c0180ffd 100644 --- a/drivers/net/iavf/iavf_ipsec_crypto.c +++ b/drivers/net/iavf/iavf_ipsec_crypto.c @@ -1518,8 +1518,11 @@ iavf_security_ctx_create(struct iavf_adapter *adapter) if (adapter->security_ctx == NULL) { adapter->security_ctx = rte_malloc("iavf_security_ctx", sizeof(struct iavf_security_ctx), 0); - if (adapter->security_ctx == NULL) + if (adapter->security_ctx == NULL) { + rte_free(adapter->vf.eth_dev->security_ctx); + adapter->vf.eth_dev->security_ctx = NULL; return -ENOMEM; + } } return 0; -- 2.33.0