Fix remaining segfaults.  Now the lingering question is whether these
changes have created (new) memory leaks?