A few fixes for memory leaks

I suggest a few fixes for memory leaks.