A few edge-case memory leak fixes and an uninitialized pointer.

Diff should be pretty straightforward.  :)