Fix memory leaks found with the static analyzer.