From 9b51779f2f964acbdc33415dc0e08f3265c64b5a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 4 Oct 2016 21:27:10 +0200 Subject: [PATCH] wibox.drawable: Fix a possible crash LGI does not protect against use-after-free issues that can occur due to using an object after finalisation. This manifests itself as occasional crashes on Travis in cairo_region_union_rectangle() (AFAIK no one ran into this issue in real-world usage). Since visible drawables are always strongly reachable, the issue can only occur with invisible drawables. The previous commit made sure that those are fully repainted when they become visible, so we can just ignore redraws for those and fix the crash issue. Signed-off-by: Uli Schlachter --- lib/wibox/drawable.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index 8c580af0..d2e10e9f 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -266,6 +266,7 @@ function drawable:set_fg(c) end function drawable:_inform_visible(visible) + self._visible = visible if visible then visible_drawables[self] = true -- The wallpaper or widgets might have changed @@ -407,13 +408,8 @@ function drawable.new(d, widget_context_skeleton, drawable_name) -- Set up our callbacks for repaints ret._redraw_callback = function(hierar, arg) - -- XXX: lgi will lead us into memory-corruption-land when we use an - -- object after it was GC'd. Try to detect this situation by checking if - -- the drawable is still valid. This is only a weak indication, but it - -- seems to be the best that we can do. The problem is that the drawable - -- could not yet be GC'd, but is pending finalisation, while the - -- cairo.Region below was already GC'd. This would still lead to corruption. - if not ret.drawable.valid then + -- Avoid crashes when a drawable was partly finalized and dirty_area is broken. + if not ret._visible then return end if ret._widget_hierarchy_callback_arg ~= arg then