Fix small memory bugs, and track the final segfault. Still some ork to do. This commit was SVN r16117.