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.
Merge pull request #426 from vadz/patch-1

Fix FILE leak if an error happens while writing pidfile.