diff --git a/simgear/io/test_untar.cxx b/simgear/io/test_untar.cxx index 153519f0..92c4ce29 100644 --- a/simgear/io/test_untar.cxx +++ b/simgear/io/test_untar.cxx @@ -33,6 +33,7 @@ void testTarGz() SG_VERIFY(TarExtractor::isTarData(buf, bufSize)); + f.close(); } void testPlainTar() @@ -48,12 +49,13 @@ void testPlainTar() SG_VERIFY(TarExtractor::isTarData(buf, bufSize)); + f.close(); } -int main (int ac, char ** av) +int main(int ac, char ** av) { testTarGz(); testPlainTar(); - return 0; + return 0; } diff --git a/simgear/io/untar.cxx b/simgear/io/untar.cxx index 0eeab2f8..e6c8a2e8 100644 --- a/simgear/io/untar.cxx +++ b/simgear/io/untar.cxx @@ -403,22 +403,26 @@ bool TarExtractor::isTarData(const uint8_t* bytes, size_t count) z.avail_in = count; if (inflateInit2(&z, ZLIB_INFLATE_WINDOW_BITS | ZLIB_DECODE_GZIP_HEADER) != Z_OK) { + inflateEnd(&z); return false; } int result = inflate(&z, Z_SYNC_FLUSH); if (result != Z_OK) { SG_LOG(SG_IO, SG_WARN, "inflate failed:" << result); + inflateEnd(&z); return false; // not tar data } size_t written = 4096 - z.avail_out; if (written < TAR_HEADER_BLOCK_SIZE) { SG_LOG(SG_IO, SG_WARN, "insufficient data for header"); + inflateEnd(&z); return false; } header = reinterpret_cast(zlibOutput); + inflateEnd(&z); } else { // uncompressed tar if (count < TAR_HEADER_BLOCK_SIZE) {