Skip to content

Commit 37f07d1

Browse files
committedApr 24, 2013
fix some file descriptor leakage bugs
1 parent 12cb5a8 commit 37f07d1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎rc.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ mytextclock = awful.widget.textclock(" %Y年%m月%d日 %H:%M:%S %A ", 1)
157157
function update_netstat()
158158
local interval = netwidget_clock.timeout
159159
local netif, text
160-
for line in io.lines("/proc/net/route") do
160+
local f = io.open('/proc/net/route')
161+
for line in f:lines() do
161162
netif = line:match('^(%w+)%s+00000000%s')
162163
if netif then
163164
break
164165
end
165166
end
167+
f:close()
168+
166169
if netif then
167170
local down, up
168-
for line in io.lines("/proc/net/dev") do
171+
f = io.open('/proc/net/dev')
172+
for line in f:lines() do
169173
-- Match wmaster0 as well as rt0 (multiple leading spaces)
170174
local name, recv, send = string.match(line, "^%s*(%w+):%s+(%d+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+(%d+)")
171175
if name == netif then
@@ -182,6 +186,7 @@ function update_netstat()
182186
break
183187
end
184188
end
189+
f:close()
185190
down = string.format('%.1f', down / 1024)
186191
up = string.format('%.1f', up / 1024)
187192
text = '↓<span color="#5798d9">'.. down ..'</span> ↑<span color="#c2ba62">'.. up ..'</span>'

0 commit comments

Comments
 (0)
Please sign in to comment.