Bug 712277 - Avoid crash in zlib adler32 following compression failure; r=michal.novotny
authorGeoff Brown <gbrown@mozilla.com>
Wed, 25 Jan 2012 14:52:29 +0100
changeset 86582 eb21d015649665642835d20085c5fe39d499567d
parent 86581 aa5578d6b29fb0b225b341335bdc699e631dabe4
child 86583 3732b1b4a0e02fb1533fcbdcebbdcf2043eef5a1
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs712277
milestone12.0a1
Bug 712277 - Avoid crash in zlib adler32 following compression failure; r=michal.novotny
netwerk/cache/nsCacheEntryDescriptor.cpp
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -910,25 +910,29 @@ nsCompressOutputStreamWrapper::Write(con
 
     // Compress (deflate) the requested buffer. Keep going
     // until the entire buffer has been deflated.
     mZstream.avail_in = count;
     mZstream.next_in = (Bytef*)buf;
     while (mZstream.avail_in > 0) {
         zerr = deflate(&mZstream, Z_NO_FLUSH);
         if (zerr == Z_STREAM_ERROR) {
+            deflateEnd(&mZstream);
+            mStreamInitialized = PR_FALSE;
             return NS_ERROR_FAILURE;
         }
         // Note: Z_BUF_ERROR is non-fatal and sometimes expected here.
 
         // If the compression stream output buffer is filled, write
         // it out to the underlying stream wrapper.
         if (mZstream.avail_out == 0) {
             rv = WriteBuffer();
             if (NS_FAILED(rv)) {
+                deflateEnd(&mZstream);
+                mStreamInitialized = PR_FALSE;
                 return rv;
             }
         }
     }
     *result = count;
     mUncompressedCount += *result;
     return NS_OK;
 }