Fix potential memory leaks.