When an ALSA device enters an inconsistent state, spa_alsa_clear()
may close log_file but later code paths (e.g., set_swparams) still
call fflush(state->log_file) or fclose(state->log_file). This can
lead to use-after-free or passing NULL to fclose, causing crashes.
Add NULL checks before fflush and fclose, and set log_file to NULL
after closing to prevent subsequent use.
Crash backtrace from an actual occurrence (invalid buf in log_write):
#0 __GI___strchrnul_lasx
#1 __GI_strcspn
#2 log_write (cookie=0x5555667f3f08, buf=0x5555670c4000, size=...)
#3 _IO_cookie_write
...
#8 set_swparams
#9 do_prepare
#10 alsa_recover