Fixed cases where file would be opened, but not closed. And small realloc memory issue.
Fix whitespace issues
Merge pull request #198 from Smilex/mem_fix

Fixed cases where file would be opened, but not closed.