Fix some warnings and a crash at exit.