awful.titlebar: Fix memory leak with clients

Any awful.titlebar.widget.button widget (e.g. floatingbutton or closebutton)
decides on the currently visible symbol based on several factors. One of them is
"is the client currently focused?" and thus the button has to be updated when
the client is focused/unfocused.

The way the code did this was to use client.connect_signal("focus", f) and
client.connect_signal("unfocus", f). However, these signals are never
disconnected and kept alive forever. The callback function had a strong
reference to the client (as an upvalue) and thus this also prevented the client
from being garbage collected.

Fix this by using c:connect_signal("focus/unfocis", f) instead. These kind of
signals are only kept alive by the client object and don't prevent it from being
garbage collected.

This fixes the new test that the previous commit added.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-01-24 13:45:06 +01:00
parent cd63cabadd
commit 791794fa42
1 changed files with 2 additions and 5 deletions

View File

@ -238,11 +238,8 @@ function titlebar.widget.button(c, name, selector, action)
-- We do magic based on whether a client is focused above, so we need to
-- connect to the corresponding signal here.
local function focus_func(o)
if o == c then update() end
end
capi.client.connect_signal("focus", focus_func)
capi.client.connect_signal("unfocus", focus_func)
c:connect_signal("focus", update)
c:connect_signal("unfocus", update)
return ret
end