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: sta...@dpdk.org

Signed-off-by: Yunjian Wang <wangyunj...@huawei.com>
---
 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

Reply via email to