Trying to diagnose and fix memory leaks.

They only happen when there is an excpetion.