Fix memory leaks (close gh-8).