Fix use-after-free when leaving invited (temporary) channels
Trac ticket 1229, https://bugs.bitlbee.org/bitlbee/ticket/1229
This one is complicated. See the trac ticket for details.
Relevant commits: cc20520 6963230 664bac3 - second one fixed the same issue, third one reverted it, this one takes a different approach.