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

Potential Graphics leak in Component$BltBufferStrategy.show

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • None
    • beta
    • generic
    • generic

      This code is on about line 3119 of Component.java

              public void show() {
                  if (backBuffers == null) {
                      return;
                  }
                  Graphics g = getGraphics();
                  for (int i = 0; i < backBuffers.length; i++) {
                      g.drawImage(backBuffers[i], 0, 0, Component.this);
                      g.dispose();
                      g = backBuffers[i].getGraphics();
                  }
                  g.dispose();
              }


      We need to wrap the Graphics we get from getGraphics and createGraphics
      calls in a try/finally block to explicitly dispose them in case of an
      exception. I suggest:

                  try {
                      for (int i = 0; i < backBuffers.length; i++) {
                          g.drawImage(backBuffers[i], 0, 0, Component.this);
                          g.dispose();
                          g = null;
                          g = backBuffers[i].getGraphics();
                      }
                  } finally {
                      if (g != null) {
                          g.dispose();
                      }
                  }

            ehawkessunw Eric Hawkes (Inactive)
            ehawkessunw Eric Hawkes (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: