Fix. Detect double calls of on_exit function.