diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx index 4053bd1..a361010 100644 --- a/common/rdr/ZlibInStream.cxx +++ b/common/rdr/ZlibInStream.cxx @@ -52,16 +52,16 @@ int ZlibInStream::pos() return offset + ptr - start; } -void ZlibInStream::removeUnderlying() +void ZlibInStream::flushUnderlying() { ptr = end = start; - if (!underlying) return; while (bytesIn > 0) { decompress(true); end = start; // throw away any data } - underlying = 0; + + setUnderlying(NULL, 0); } void ZlibInStream::reset() @@ -90,7 +90,7 @@ void ZlibInStream::init() void ZlibInStream::deinit() { assert(zs != NULL); - removeUnderlying(); + setUnderlying(NULL, 0); inflateEnd(zs); delete zs; zs = NULL; @@ -100,8 +100,6 @@ int ZlibInStream::overrun(int itemSize, int nItems, bool wait) { if (itemSize > bufSize) throw Exception("ZlibInStream overrun: max itemSize exceeded"); - if (!underlying) - throw Exception("ZlibInStream overrun: no underlying stream"); if (end - ptr != 0) memmove(start, ptr, end - ptr); @@ -127,6 +125,9 @@ int ZlibInStream::overrun(int itemSize, int nItems, bool wait) bool ZlibInStream::decompress(bool wait) { + if (!underlying) + throw Exception("ZlibInStream overrun: no underlying stream"); + zs->next_out = (U8*)end; zs->avail_out = start + bufSize - end; diff --git a/common/rdr/ZlibInStream.h b/common/rdr/ZlibInStream.h index 6bd4da4..86ba1ff 100644 --- a/common/rdr/ZlibInStream.h +++ b/common/rdr/ZlibInStream.h @@ -38,7 +38,7 @@ namespace rdr { virtual ~ZlibInStream(); void setUnderlying(InStream* is, int bytesIn); - void removeUnderlying(); + void flushUnderlying(); int pos(); void reset(); diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index cc786f5..e2a99da 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -340,7 +340,8 @@ void TightDecoder::decodeRect(const Rect& r, const void* buffer, zis[streamId].readBytes(netbuf, dataSize); - zis[streamId].removeUnderlying(); + zis[streamId].flushUnderlying(); + zis[streamId].setUnderlying(NULL, 0); delete ms; bufptr = netbuf; diff --git a/common/rfb/zrleDecode.h b/common/rfb/zrleDecode.h index 32b5c92..f432538 100644 --- a/common/rfb/zrleDecode.h +++ b/common/rfb/zrleDecode.h @@ -174,7 +174,8 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is, } } - zis->removeUnderlying(); + zis->flushUnderlying(); + zis->setUnderlying(NULL, 0); } #undef ZRLE_DECODE