fixed segfault caused by fclose on null file