Re: [dev] [dwm] Question regarding `unmanage()` in while loop

From: Alexander Monakov <amonakov_AT_ispras.ru>
Date: Thu, 4 Aug 2016 15:30:53 +0300 (MSK)

On Wed, 3 Aug 2016, Paul Menzel wrote:
> dwm.c:480:4: warning: Use of memory after it is freed
> unmanage(m->stack, 0);
> ^~~~~~~~~~~~~~~~~~~~~

I think the warning is correct: after m->stack is free'd in unmanage, the
subsequent 'focus(NULL)' call in unmanage will dereference m->stack if
'm' happened to match 'selmon'. It's possible that a similar dereference can
happen via other paths if 'm' is different from 'selmon'.

In any case, you should be able to confirm it by running dwm under Address
Sanitizer or Valgrind and invoking the 'quit' procedure (bound to Mod-Shift-q by
default), unless you hit some other error first.

Note,

> void
> cleanup(void)
> {
[...]
> for (m = mons; m; m = m->next)
> if (m->stack)
> unmanage(m->stack, 0);

this bit seems to be misquoting dwm source: afaics dwm has 'while' rather than
'if', and the rest of your email is worded as if you (correctly) had a 'while'
there.

Alexander
Received on Thu Aug 04 2016 - 14:30:53 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 04 2016 - 14:36:17 CEST