The changes are more extensive that I'd planned so I'd appreciate some
careful review. Basically, the total_read variable turned out to be
completely pointless. Once I'd fixed the leftovers processing so that
it returned if there was any data, I couldn't work out how it could be
anything other than 0 for most of it's lifetime. The only time it was
incremented was just after we read data; a situation where we have to
return without reading any more data. So I got rid of it.

I'm still a little unsure of the code that deals with
freeing/iterating chunks. Especially in the case where the read was
short (short != EOF). Especially especially in the case where the
read was 0 (also 0 != EOF). So could reviewing eyes pay that aspect
particular attention.