Fix problems discovered by coverity (and more):
A part of !615 (closed) separated according to request.
- Better handling of data pointer and errors for compressed data in kitty protocol
- Correct handling of iterator when erasing a placement.
- Use midRef() instead of mid().