net/pcap: fix resource leakage on port probe

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.

Fixes: 4c173302c3 ("pcap: add new driver")
Cc: stable@dpdk.org

Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Qiming Chen 2021-08-30 11:01:08 +08:00 committed by Ferruh Yigit
parent 30b4d95a29
commit da0280b3a3

View File

@ -1362,6 +1362,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)
{
@ -1582,6 +1609,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;
}