[06/20] net/bnxt: fix 'ctx' memory leak when new malloc fail

Message ID tencent_9734EB7C7D678E9889E4C4F8F15C9F72470A@qq.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series fix memory leaks in error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Weiguo Li Feb. 22, 2022, 6:18 p.m. UTC
  When new memory is not available and the memory "ctx" allocated
beforehand was not assigned to anywhere, so "ctx" should be freed,
otherwise will cause a memory leak.

Fixes: b4f740511655 ("net/bnxt: remove unnecessary return check")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/net/bnxt/bnxt_hwrm.c | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index b4aeec593e..4993111ccf 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -5374,6 +5374,7 @@  int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
 			    RTE_CACHE_LINE_SIZE);
 	if (!ctx_pg) {
 		rc = -ENOMEM;
+		rte_free(ctx);
 		goto ctx_err;
 	}
 	for (i = 0; i < tqm_rings; i++, ctx_pg++)