Fix FILE leak if an error happens while writing pidfile.

Call fclose() even if writing to the PID file failed, otherwise it was simply leaked in this case.