Fixed some potential memory leaks.