Bug 729326 - Errors found using a static code analysis program cppcheck

Fixed some memory and file leaks. And removed some code and variables
that are not used.