Fix potential leak when executing a WriteTask fails.