Skip to content

Commit

Permalink
core: fix memory leak in _draw_callback
Browse files Browse the repository at this point in the history
Fixes the following memory leak reported by valgrind:

    992 bytes in 31 blocks are definitely lost in loss record 81 of 111
       at 0x483577F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
       by 0x49DB0DD: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
       by 0x49D8FB4: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
       by 0x49DA63E: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
       by 0x49DA751: xcb_wait_for_reply (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
       by 0x118094: _draw_callback (compton.c:1335)
       by 0x1184D0: draw_callback (compton.c:1426)
       by 0x49BF292: ev_invoke_pending (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
       by 0x49C3344: ev_run (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
       by 0x11AD65: session_run (compton.c:2226)
       by 0x11B005: main (compton.c:2308)

To prevent accidentaly reusing the freed structure, wrap it in a lexical
scope.
  • Loading branch information
liskin authored and yshui committed Sep 21, 2019
1 parent 1395b76 commit e55d1d4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,12 @@ static void _draw_callback(EV_P_ session_t *ps, int revents) {
// Call fill_win on new windows
handle_new_windows(ps);

auto r = xcb_get_input_focus_reply(ps->c, xcb_get_input_focus(ps->c), NULL);
if (!ps->active_win || (r && r->focus != ps->active_win->base.id)) {
recheck_focus(ps);
{
auto r = xcb_get_input_focus_reply(ps->c, xcb_get_input_focus(ps->c), NULL);
if (!ps->active_win || (r && r->focus != ps->active_win->base.id)) {
recheck_focus(ps);
}
free(r);
}

// Refresh pixmaps
Expand Down

0 comments on commit e55d1d4

Please sign in to comment.