Fix various memory leaks.