From 85aa507f737b99501bb91cf79985af78f46ff0be Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 6 Jan 2016 17:49:49 +0100 Subject: Avoid memory leaks upon (de)compression failure This e.g. reduces the LSan-reported leakage during CppunitTest_sd_filters_test from SUMMARY: AddressSanitizer: 504104 byte(s) leaked in 4654 allocation(s). to SUMMARY: AddressSanitizer: 115048 byte(s) leaked in 4639 allocation(s). Change-Id: If922e872d9f696847face198e082144ccd5f12de --- tools/source/zcodec/zcodec.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/source/zcodec/zcodec.cxx b/tools/source/zcodec/zcodec.cxx index 7a983aaf9392..f11f7898ef15 100644 --- a/tools/source/zcodec/zcodec.cxx +++ b/tools/source/zcodec/zcodec.cxx @@ -82,17 +82,20 @@ long ZCodec::EndCompression() { long retvalue = 0; - if (mbStatus && meState != STATE_INIT) + if (meState != STATE_INIT) { if (meState == STATE_COMPRESS) { - do + if (mbStatus) { + do + { + ImplWriteBack(); + } + while ( deflate( PZSTREAM, Z_FINISH ) != Z_STREAM_END ); + ImplWriteBack(); } - while ( deflate( PZSTREAM, Z_FINISH ) != Z_STREAM_END ); - - ImplWriteBack(); retvalue = PZSTREAM->total_in; deflateEnd( PZSTREAM ); -- cgit v1.2.3