DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [RFC V1] examples/l3fwd-power: fix memory leak for rte_pci_device
@ 2021-09-07  3:41 Huisong Li
  2021-09-07  8:53 ` Thomas Monjalon
  0 siblings, 1 reply; 17+ messages in thread
From: Huisong Li @ 2021-09-07  3:41 UTC (permalink / raw)
  To: dev; +Cc: thomas, ferruh.yigit, david.marchand, lihuisong

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@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


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-10-08  6:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07  3:41 [dpdk-dev] [RFC V1] examples/l3fwd-power: fix memory leak for rte_pci_device Huisong Li
2021-09-07  8:53 ` Thomas Monjalon
2021-09-08  2:01   ` Huisong Li
2021-09-08  7:20     ` Thomas Monjalon
2021-09-16  8:01       ` Huisong Li
2021-09-16 10:36         ` Thomas Monjalon
2021-09-17  2:13           ` Huisong Li
2021-09-17 12:50             ` Thomas Monjalon
2021-09-18  3:24               ` Huisong Li
2021-09-18  8:46                 ` Thomas Monjalon
2021-09-26 12:20                   ` Huisong Li
2021-09-26 19:16                     ` Thomas Monjalon
2021-09-27  1:44                       ` Huisong Li
2021-09-30  6:28                         ` Huisong Li
2021-09-30  7:50                           ` Thomas Monjalon
2021-10-08  6:26                             ` lihuisong (C)
2021-10-08  6:29                               ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).