If close of a file fails, the counters would be incremented even when the file has not been closed. So thought it would be better if we increment counters only if v are able to open a new file after closing the previous file.