Merge pull request #2 from rrebello/master

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