Fix crash at shutdown.