Fix some memleaks at exit