From: Qiming Chen <chenqiming_huawei@163.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, Qiming Chen <chenqiming_huawei@163.com>
Subject: [dpdk-dev] [PATCH] net/pcap: solve pcap resource leakage when port probe
Date: Mon, 30 Aug 2021 10:54:42 +0800 [thread overview]
Message-ID: <20210830025442.3310-1-chenqiming_huawei@163.com> (raw)
When the port is probed, if the eth_from_pcaps function fails, the
previously opened pcap resources are not released, causing resource
leakage.
The patch solves the problem of resource leakage caused by abnormal
branch exit during the port probe process.
Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
---
drivers/net/pcap/pcap_ethdev.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index fdc74313d5..163e583f7f 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -1410,6 +1410,33 @@ eth_from_pcaps(struct rte_vdev_device *vdev,
return 0;
}
+static void
+eth_release_pcaps(struct pmd_devargs *pcaps,
+ struct pmd_devargs *dumpers,
+ int single_iface)
+{
+ unsigned int i;
+
+ if (single_iface) {
+ if (pcaps->queue[0].pcap)
+ pcap_close(pcaps->queue[0].pcap);
+ return;
+ }
+
+ for (i = 0; i < dumpers->num_of_queue; i++) {
+ if (dumpers->queue[i].dumper)
+ pcap_dump_close(dumpers->queue[i].dumper);
+
+ if (dumpers->queue[i].pcap)
+ pcap_close(dumpers->queue[i].pcap);
+ }
+
+ for (i = 0; i < pcaps->num_of_queue; i++) {
+ if (pcaps->queue[i].pcap)
+ pcap_close(pcaps->queue[i].pcap);
+ }
+}
+
static int
pmd_pcap_probe(struct rte_vdev_device *dev)
{
@@ -1639,6 +1666,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
free_kvlist:
rte_kvargs_free(kvlist);
+ if (ret < 0)
+ eth_release_pcaps(&pcaps, &dumpers, devargs_all.single_iface);
+
return ret;
}
--
2.30.1.windows.1
next reply other threads:[~2021-08-30 2:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-30 2:54 Qiming Chen [this message]
2021-08-30 3:01 ` [dpdk-dev] [PATCH v2] " Qiming Chen
2021-09-09 13:02 ` Ferruh Yigit
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=20210830025442.3310-1-chenqiming_huawei@163.com \
--to=chenqiming_huawei@163.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
/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).