Check for valid handle before calling fclose().