fix segfault: fclose(NULL)