core: don't accidentally unref a varlink connection twice
Let's make sure that our close handler unrefs a connection again that we
are already unreffing a few stack frames up by invalidating the pointer
first, and dropping the ref counter only after that.
Replaces: 39ad3f1c092b5dffcbb4b1d12eb9ca407f010a3c
Fixes: #18025
(cherry picked from commit d65e974e67e47222cdebd9d0b6becd6642547ce2)