From 53b8ed48bf0ccc39ce432fda0ac3a391949fec46 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sat, 25 Sep 2021 20:32:53 +0200 Subject: [PATCH] Kobo: Don't leak fds in isWifiOn io.lines only closes the fd when the loop is exited sanely, not by a control flow keyword (i.e., no break or return allowed). Regression since #8169 --- frontend/device/kobo/device.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 9e49b1ce0..71b3160a6 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -508,12 +508,20 @@ function Kobo:initNetworkManager(NetworkMgr) -- We could alternatively check if lfs.attributes("/proc/sys/net/ipv4/conf/" .. os.getenv("INTERFACE"), "mode") == "directory" -- c.f., also what Cervantes does via /sys/class/net/eth0/carrier to check if the interface is up. -- That said, since we only care about whether *modules* are loaded, this does the job nicely. - for haystack in io.lines("/proc/modules") do + local f = io.open("/proc/modules", "re") + if not f then + return false + end + + local found = false + for haystack in f:lines() do if haystack:sub(1, nlen) == needle then - return true + found = true + break end end - return false + f:close() + return found end end