Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6687968

PNGImageReader leaks native memory through an Inflater.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 7
    • 5.0, 6, 6u7
    • client-libs
    • b43
    • x86, sparc
    • linux, solaris_10

        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 ----------

              bae Andrew Brygin
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: