Fix several memory leaks.