Fixes some memory leaks.