Fix memory leak in wal_writer_thread