mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
Use file:lines() instead of io.lines(filename) API
This is due to a very strange quirk in Lua. If we use io.lines(filename) API like this: for line in io.lines(filename) do .... if something then break end end Then the file descriptor table is growing infinitely because the descriptor is not closed on breaking out of io.lines() loop. So we have to use the ordinary file api like this: local file = io.open(filename, "r") for line in file:lines() do .... if something then break end end file:close() This way there is no file descriptor leak.
This commit is contained in:
parent
83fb0cd69b
commit
bef40656a6
@ -2187,7 +2187,8 @@ end
|
||||
-- returns five numbers (in KB): rss, data, stack, lib, totalvm
|
||||
function memUsage()
|
||||
local rss, data, stack, lib, totalvm = -1, -1, -1, -1, -1
|
||||
for line in io.lines("/proc/self/status") do
|
||||
local file = io.open("/proc/self/status", "r")
|
||||
for line in file:lines() do
|
||||
local s, n
|
||||
s, n = line:gsub("VmRSS:%s-(%d+) kB", "%1")
|
||||
if n ~= 0 then rss = tonumber(s) end
|
||||
@ -2209,6 +2210,7 @@ function memUsage()
|
||||
break
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
return rss, data, stack, lib, totalvm
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user