Fix memory leaks introduced in previous commits.