Don't leave dangling pointers in Free functions

While these are mostly called during teardown of larger structures
that are about to themselves be freed, there's no guarantee that
will always be the case, so try to be safer here.

[ This bug was found by the Parfait 4.0 bug checking tool. ]

v2: Deduplicate & simplify pointer clearing in _XFreeEventCookies
    as suggested by @keithp

Signed-off-by: Alan Coopersmith <>
4 jobs for parfait-fixes in 6 minutes and 49 seconds (queued for 3 seconds)