Fixing various memory leaks.