Fix crash on app exit.