fix crash at exit