JDK-6687968 : PNGImageReader leaks native memory through an Inflater.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0,6,6u7
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,solaris_10
  • CPU: x86,sparc
  • Submitted: 2008-04-14
  • Updated: 2011-01-19
  • Resolved: 2009-01-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u18-revFixed 6u13-revFixed 7 b43Fixed
Related Reports
Relates :  
Description
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 ----------

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/java2d_data/7/6687968.0
2008-07-25

EVALUATION Its not strictly a leak, its less than prompt finalization The code that creates the Inflater instance is presumably doing so precisely so that it can release that resource in a timely manner without closing the client-supplied input stream, but it fails to do. When not explicitly providing an Inflater instance InflaterInputStream instances need to be close()'d asap to release the Inflater instance. This needs to be done in one other place in PNGImageReader.
2008-07-22