[dpdk-dev] [RFC V1] examples/l3fwd-power: fix memory leak for rte_pci_device

Huisong Li lihuisong at huawei.com
Tue Sep 7 05:41:08 CEST 2021


Calling rte_eth_dev_close() will release resources of eth device and close
it. But rte_pci_device struct isn't released when app exit, which will lead
to memory leak.

Fixes: 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")

Signed-off-by: Huisong Li <lihuisong at huawei.com>
---
 examples/l3fwd-power/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index aa7b8db44a..6498b5225e 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2512,6 +2512,8 @@ main(int argc, char **argv)
 	struct lcore_conf *qconf;
 	struct rte_eth_dev_info dev_info;
 	struct rte_eth_txconf *txconf;
+	struct rte_eth_dev *eth_dev;
+	struct rte_device *rte_dev;
 	int ret;
 	uint16_t nb_ports;
 	uint16_t queueid;
@@ -2910,7 +2912,14 @@ main(int argc, char **argv)
 			RTE_LOG(ERR, L3FWD_POWER, "rte_eth_dev_stop: err=%d, port=%u\n",
 				ret, portid);
 
+		/* Retrieve device address in eth device before closing it. */
+		eth_dev = &rte_eth_devices[portid];
+		rte_dev = eth_dev->device;
 		rte_eth_dev_close(portid);
+		ret = rte_dev_remove(rte_dev);
+		if (ret != 0)
+			RTE_LOG(ERR, L3FWD_POWER, "rte_dev_remove: err=%d, port=%u\n",
+				ret, portid);
 	}
 
 	if (app_mode == APP_MODE_EMPTY_POLL)
-- 
2.33.0



More information about the dev mailing list