logwriter: fixed a double-free issue in case of a flush error happens

This patch fixes a double-free and possible use-after-free issue in case
an error happens when writing a file on disk. The easiest way to reproduce
is to fill a disk, then wait time_reopen() seconds.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>