From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E75BEA0547; Mon, 30 Aug 2021 04:56:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3D944068A; Mon, 30 Aug 2021 04:56:08 +0200 (CEST) Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by mails.dpdk.org (Postfix) with ESMTP id 0213240142 for ; Mon, 30 Aug 2021 04:56:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=KIH1v hKhiyeLhaEelgQwvCPOIc3zm2Kx/koHOwVjO28=; b=DeU9sxUfh+33b+ejzB/YB B0/JZtTd2K4AztuqjimQ6yVQBvd0DFE9OFQcW3uBWh0IgjoBrH3ofjaQfI79garu xlSQ4PrAMYRxzl1w66wfyhlL2OFpImMKN/MG9fLEtwDIluTikuzrITf1QuTq5PtX l7KwGA0YyEe4xGWrWXvf9c= Received: from localhost.localdomain (unknown [124.160.214.152]) by smtp2 (Coremail) with SMTP id GtxpCgCXxSC+SCxhJ+QnQg--.41370S2; Mon, 30 Aug 2021 10:56:02 +0800 (CST) From: Qiming Chen To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Qiming Chen Date: Mon, 30 Aug 2021 10:54:42 +0800 Message-Id: <20210830025442.3310-1-chenqiming_huawei@163.com> X-Mailer: git-send-email 2.30.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgCXxSC+SCxhJ+QnQg--.41370S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww1ktFyrZrWxZFWUGF43trb_yoW8WrW7pF 43KFy5Ka18Xr1fWwsxCF4UuryfXaySqrW7trWfG34fuw4xAry3Xry8uFyayrs5Gr18Ka12 yr1DGrWDGr97AwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b4E_NUUUUU= X-Originating-IP: [124.160.214.152] X-CM-SenderInfo: xfkh01xlpl0w5bkxt4lhl6il2tof0z/1tbiNgL+oFWBn9oXIAAAsM Subject: [dpdk-dev] [PATCH] net/pcap: solve pcap resource leakage when port probe X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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