Fixed a file handle leak (found by cppcheck)