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

Potential graphics leak in RepaintArea.java

XMLWordPrintable

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

      In /src/share/classes/sun/awt/RepaintArea.java, we are potentially
      leaking a Graphics. In the code below, the test for isEmpty()
      should be done inside the try-finally block in order to make sure the
      graphics obtained by use of comp.getGraphics() is properly disposed.

          public void paint(Object target, boolean isClearRectOnPaint) {
              Component comp = (Component)target;
              Graphics g = comp.getGraphics();
              if (g == null || isEmpty()) {
                  return;
              }
              try {
                  RepaintArea ra = this.cloneAndReset();
                  int numRects = ra.rectangleList.size();
                  union[HORIZONTAL] = union[VERTICAL] = null;
                  for (int nRect = 0; nRect < numRects; nRect++) {
                      Rectangle r = (Rectangle) ra.rectangleList.removeFirst();
                      int addTo = (r.width > r.height) ? HORIZONTAL : VERTICAL;
                      if (union[addTo] == null) {
                          union[addTo] = r;
                      } else {
                          union[addTo].add(r);
                      }
                  }
                  if(union[HORIZONTAL] != null && union[VERTICAL] != null) {
                      int square = ra.width * ra.height;
                      int benefit = square - union[HORIZONTAL].width*union[HORIZONTAL].height
                          - union[VERTICAL].width*union[VERTICAL].height;
                      // if benefit is comparable with bounding box
                      if (MAX_BENEFIT_RATIO * benefit > square) {
                          paintRect(comp, g, union[HORIZONTAL], isClearRectOnPaint);
                          paintRect(comp, g, union[VERTICAL], isClearRectOnPaint);
                          return;
                      }
                  }
                  paintRect(comp, g, ra, isClearRectOnPaint);
              } finally {
                  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: