1

I found that for some case (GZIPInputStream throw IOException), there is a leak - Inflater member of GZIPInputStream which is constructed in first statement is not released correctly via function "end()". In this case, GZIPInputStream is not constructed, so calling function cannot close it. Is GZIPInputStream really wrong?

public GZIPInputStream(InputStream is, int size) throws IOException {
    super(is, new Inflater(true), size);
    byte[] header = new byte[10];
    readFully(header, 0, header.length);
    int magic = getShort(header, 0);
    if (magic != GZIP_MAGIC) {
        throw new IOException(String.format("unknown format (magic number %x)", magic));
    }
    ......
}
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
user941884
  • 21
  • 5
  • which implementation of `GZIPInputStream`, when is it not released correctly? The code sample does not match your description, as far as I can see. – David O'Meara May 08 '12 at 07:08
  • It is an Android implementation. It is in a release of Android source code (e.g., Gingerbread). – user941884 May 08 '12 at 07:38
  • The inflater may be closed by the super implementation. Otherwise, this really would be a serious issue because of the native resources Inflater allocates. – Michael Schmeißer May 08 '12 at 07:51
  • Below is declaration of Inflater.end(). It seems that end() shoud be invoked explicitly. ` /** * Releases resources associated with this {@code Inflater}. Any unused * input or output is discarded. This method should be called explicitly in * order to free native resources as soon as possible. After {@code end()} is * called, other methods will typically throw {@code IllegalStateException}. */ public synchronized void end()` – user941884 May 09 '12 at 02:16

0 Answers0