Miscellaneous memory leak/unitnitialized variable fixes.

Just a few fixes. 

I've separated them so they can be reviewed easier. I can squash them all into one commit however if you want.