[PATCH v3 5/8] ml/cnxk: fix potential memory leak in xstats

Srikanth Yalavarthi syalavarthi at marvell.com
Thu Mar 16 22:29:01 CET 2023


Local buffer xstats_map is not released, when the xstats name
passed by the user application is not valid. This patch releases
the memory in such cases.

Fixes: 4ff4ab8e1a20 ("ml/cnxk: support extended statistics")

Signed-off-by: Srikanth Yalavarthi <syalavarthi at marvell.com>
---
 drivers/ml/cnxk/cn10k_ml_ops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c
index 8d31276e8c..4df2ca0e8c 100644
--- a/drivers/ml/cnxk/cn10k_ml_ops.c
+++ b/drivers/ml/cnxk/cn10k_ml_ops.c
@@ -1128,8 +1128,10 @@ cn10k_ml_dev_xstats_by_name_get(struct rte_ml_dev *dev, const char *name, uint16
 		}
 	}
 
-	if (id == PLT_DIM(cn10k_ml_model_xstats_table) * dev_info.max_models)
+	if (id == PLT_DIM(cn10k_ml_model_xstats_table) * dev_info.max_models) {
+		rte_free(xstats_map);
 		return -EINVAL;
+	}
 
 	model_id = id / PLT_DIM(cn10k_ml_model_xstats_table);
 	type = id % PLT_DIM(cn10k_ml_model_xstats_table);
-- 
2.17.1



More information about the dev mailing list