Stop use-after-free in event loop termination.