From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ilya Maximets Subject: [PATCH v3 1/2] eal/bsd: fix possible IOPL fd leak Date: Fri, 23 Nov 2018 18:39:19 +0300 Message-ID: <20181123153920.12398-2-i.maximets@samsung.com> References: <20181123143620.10480-1-i.maximets@samsung.com> <20181123153920.12398-1-i.maximets@samsung.com> Content-Type: text/plain; charset="utf-8" Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang , Thomas Monjalon , Ferruh Yigit , Ian Stokes , Kevin Traynor , Bruce Richardson , Ilya Maximets , stable@dpdk.org To: dev@dpdk.org, David Marchand Return-path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 12BC41B5D4 for ; Fri, 23 Nov 2018 16:39:50 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181123153949euoutp02fb963ddfb1997c746a6e13072f77e96d~pywmSCt1V1137211372euoutp02X for ; Fri, 23 Nov 2018 15:39:49 +0000 (GMT) In-Reply-To: <20181123153920.12398-1-i.maximets@samsung.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If rte_eal_iopl_init() will be called more than once we'll leak the file descriptor. Fixes: b46fe31862ec ("eal/bsd: fix virtio on FreeBSD") Cc: stable@dpdk.org Signed-off-by: Ilya Maximets --- lib/librte_eal/bsdapp/eal/eal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 508cbc46f..b8152a75c 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -556,9 +556,11 @@ int rte_eal_has_hugepages(void) int rte_eal_iopl_init(void) { - static int fd; + static int fd = -1; + + if (fd < 0) + fd = open("/dev/io", O_RDWR); - fd = open("/dev/io", O_RDWR); if (fd < 0) return -1; /* keep fd open for iopl */ -- 2.17.1