Only closes the file pointer if the file was opened.