add fclose before unlink

add fclose before unlink