Fixed a crash that could happen if the client disconnects while a chunked response is being sent.

Fixes issue #1062.