Fix some resource leak issues and remove unnecessary fflush() calls (fclose() does the job on its own).
Merge pull request #2 from rrebello/master

"Small" fixes: Memory leaks and unnecessary fflush() calls