DPDK patches and discussions
 help / color / mirror / Atom feed
From: Wenjun Wu <wenjun1.wu@intel.com>
To: dev@dpdk.org, anatoly.burakov@intel.com, qi.z.zhang@intel.com
Cc: simei.su@intel.com, Wenjun Wu <wenjun1.wu@intel.com>, stable@dpdk.org
Subject: [PATCH v1 2/2] examples/multi_process: fix memory leak
Date: Wed,  5 Jul 2023 17:25:11 +0800	[thread overview]
Message-ID: <20230705092511.362484-3-wenjun1.wu@intel.com> (raw)
In-Reply-To: <20230705092511.362484-1-wenjun1.wu@intel.com>

The device should be detached before quit, otherwise it will
cause memory leak.

Fixes: 05f1d6842fc3 ("examples/multi_process: add hotplug sample")
Cc: stable@dpdk.org

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
---
 examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
index 88f44e00a0..143d57eeb6 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
+	uint16_t port_id;
+	char dev_name[RTE_DEV_NAME_MAX_LEN];
+	struct rte_devargs da;
+
+	RTE_ETH_FOREACH_DEV(port_id) {
+		rte_eth_dev_get_name_by_port(port_id, dev_name);
+		memset(&da, 0, sizeof(da));
+
+		if (rte_devargs_parsef(&da, "%s", dev_name)) {
+			cmdline_printf(cl,
+				       "cannot parse devargs for device %s\n",
+				       dev_name);
+		}
+		printf("detaching before quit...\n");
+		if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
+			cmdline_printf(cl, "detached device %s\n",
+				da.name);
+		else
+			cmdline_printf(cl, "failed to detach device %s\n",
+				da.name);
+
+	}
 	cmdline_quit(cl);
 }
 
-- 
2.34.1


  parent reply	other threads:[~2023-07-05  9:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05  9:25 [PATCH v1 0/2] " Wenjun Wu
2023-07-05  9:25 ` [PATCH v1 1/2] bus/vdev: " Wenjun Wu
2023-07-06  0:48   ` fengchengwen
2023-07-05  9:25 ` Wenjun Wu [this message]
2023-07-06  1:02   ` [PATCH v1 2/2] examples/multi_process: " fengchengwen
2023-07-06  5:10     ` Wu, Wenjun1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230705092511.362484-3-wenjun1.wu@intel.com \
    --to=wenjun1.wu@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=simei.su@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).