Fixed memory leaks introduced in the last few commits.