FULL PRODUCT VERSION :
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Any OS which exhibits Bug #4797189.
A DESCRIPTION OF THE PROBLEM :
Line 1228 of PNGImageReader creates a new Inflater and passes it into an InflaterInputStream:
is = new InflaterInputStream(is, new Inflater());
Inspection of the InflaterInputStream code reveals that this Inflater will never be "end"ed, even by a call to "close", causing a leak of memory as described in Bug #4797189.
A reference to the Inflater should be maintained and properly "end"ed in the "PNGImageReader .dispose" method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program to reproduce.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected normal heap usage.
ACTUAL -
Actual heap usage mimics that of Bug #4797189.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.imageio.ImageReadParam;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;
import com.sun.imageio.plugins.png.PNGImageReader;
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
public class Leak
{
public static void main(String[] args) throws Exception
{
while (true)
{
ImageInputStream stream = new FileImageInputStream(new File("image.png"));
PNGImageReader imageReader = new PNGImageReader(new PNGImageReaderSpi());
imageReader.setInput(stream);
imageReader.read(0, new ImageReadParam());
imageReader.dispose();
stream.close();
}
}
}
---------- END SOURCE ----------