Fix some memory leaks at exit