brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

Segfault on shutdown with cairo_xlib_surface_create #1203

Closed dubrowgn closed 2 years ago

dubrowgn commented 2 years ago

Issue

Since upgrading to Linux Mint 21, I have noticed conky crashes on shutdown and reload. Effectively this means conky crashes any time you touch .conkyrc, etc.

Running under valgrind seems to indicate some kind of memory corruption has occurred, causing an invalid jump inside of xlib.

$ valgrind conky -D
...
conky: received SIGHUP, SIGINT, or SIGTERM to terminate. bye!
...
DEBUG(0) [./src/x11.cc:436]: deinit_X11()
==608376== Jump to the invalid address stated on the next line
==608376==    at 0x9CA7EC0: ???
==608376==    by 0x4C2A851: XCloseDisplay (ClDisplay.c:65)
==608376==    by 0x175D8C: ??? (in /usr/bin/conky)
==608376==    by 0x130CCA: ??? (in /usr/bin/conky)
==608376==    by 0x133AF0: ??? (in /usr/bin/conky)
==608376==    by 0x1247F5: main (in /usr/bin/conky)
==608376==  Address 0x9ca7ec0 is not stack'd, malloc'd or (recently) free'd
==608376== 
==608376== 
==608376== Process terminating with default action of signal 11 (SIGSEGV)
==608376==  Access not within mapped region at address 0x9CA7EC0
==608376==    at 0x9CA7EC0: ???
==608376==    by 0x4C2A851: XCloseDisplay (ClDisplay.c:65)
==608376==    by 0x175D8C: ??? (in /usr/bin/conky)
==608376==    by 0x130CCA: ??? (in /usr/bin/conky)
==608376==    by 0x133AF0: ??? (in /usr/bin/conky)
==608376==    by 0x1247F5: main (in /usr/bin/conky)

Interestingly, I can avoid the crash by removing a call to cairo_xlib_surface_create in my lua code. I don't have to do anything with the surface, just create it. Calling cairo_surface_destroy has no effect.

-- .conkyrc
conky.config = {
    ...
    lua_load = '~/.conky/main.lua',
    lua_draw_hook_post = 'draw',
    ...
}

-- .conky/main.lua
require('cairo')

function conky_draw()
    if conky_window == nil then
        return
    end

    local surface = cairo_xlib_surface_create(
        conky_window.display,
        conky_window.drawable,
        conky_window.visual,
        conky_window.width,
        conky_window.height
    )
end

If I remove the creation of this surface, conky no longer segfaults on shutdown. It's not clear if this is directly related, or simply changing memory layout enough to avoid the segfault.

Information

Current Linux Mint 21 install, running upstream ubuntu 22.04's xlib v1.7.5-1 and conky 1.12.2-1.

I can reproduce this on 3 different sets of hardware, with both Nvidia and AMD gpu's.

Attempting to get more debug information, I compiled the same version of conky from source with debug symbols, but I was unable to reproduce the issue with my custom binary. Given the nature of memory corruption issues, this is unfortunate, but not entirely surprising.

dubrowgn commented 2 years ago

Thanks @brndnmtthws!