Memory Leak Patch

I've added some *free() calls to prevent some memory leaks. My editor also automatically made some cosmetic changes which can be ignored.