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 DA7F8A0547; Mon, 30 Aug 2021 05:01:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 634314068A; Mon, 30 Aug 2021 05:01:56 +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 471BE40142 for ; Mon, 30 Aug 2021 05:01:54 +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=c4EAV b2RiISBTnilVEmQBQmjwlrIFq//Z/uz5kHGUng=; b=UhfbR7BSj9TssinqZDGyt ntuueVMpbk18z9OoCXx9nj+KRnCMDRYNOtouMWfpVtgGvbluDq9E0GkOw+cwHLCd i74+R4iXQk+lQGftvKyMBxKZUwHmDsnhkzSr6tUOzZ/0+QhSORgtNDOxeal/pf1B w8sSp8E4S1PIq/7g5k5Nl4= Received: from localhost.localdomain (unknown [124.160.214.152]) by smtp2 (Coremail) with SMTP id GtxpCgC3SfwdSixhNYYoQg--.40599S2; Mon, 30 Aug 2021 11:01:52 +0800 (CST) From: Qiming Chen To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Qiming Chen Date: Mon, 30 Aug 2021 11:01:08 +0800 Message-Id: <20210830030108.3367-1-chenqiming_huawei@163.com> X-Mailer: git-send-email 2.30.1.windows.1 In-Reply-To: <20210830025442.3310-1-chenqiming_huawei@163.com> References: <20210830025442.3310-1-chenqiming_huawei@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgC3SfwdSixhNYYoQg--.40599S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww1ktFyrZrWxZFWUGF43trb_yoW8WFy7pF 43KF98Ka18Xr1fWwsxCF48ur1SqayftrW7trWfG343ur4fAFy3Xry8uF1ayrs5Gr18KF42 yr1DGr4kGr97ArUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b4BMNUUUUU= X-Originating-IP: [124.160.214.152] X-CM-SenderInfo: xfkh01xlpl0w5bkxt4lhl6il2tof0z/1tbiNgD+oFWBn9okgwAAse Subject: [dpdk-dev] [PATCH v2] 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 --- v2: Clear coding style warning. --- 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..4756eecda8 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