Scanner problems

1) restore the scanner's original cursor position in case of
   insufficient input;
2) free the memories allocated for a new header in case of a failure.
(cherry picked from commit 7a571f513e801f071873f2627400461b04213b13)
Avoid malicious client exploit to exhaust the device's memory

Suppose the UPnP device is listening on 192.168.1.102:49152. Use the following to send
garbage bytes to the device:
while true; do echo "\""; done | netcat 192.168.1.102 49152

The device just keeps receiving these bytes and its memory usage keeps growing.
Malicious client may exploit it to exhaust the device's memory.

The attached patch eliminates this possibility.
(cherry picked from commit 9a9c4e829ea059bafc80d5fb568223a8b2068b28)