Fix incorrect tile access in KisPaintDevice::clearSelection()
purge() must be called if and only if no other actor still accesses
the same tile. Therefore, the iterators should be destroyed before
calling to purge.
Theoretically this problem may lead to incorrect undo history
being written, though I couldn't imagine how (yet).