Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-10221 Resorce leak problems in JBossTools
  3. JBIDE-10229

org.jboss.tools.jst.css.dialog.ImageSelectionDialog has GC leaks logik

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Done
    • Major
    • 3.3.0.M5
    • 3.3.0.M4
    • common
    • None

    Description

              canvas.addPaintListener(new PaintListener() {
                      public void paintControl(PaintEvent e) {
                          GC gc = new GC(canvas);                                           <-------------------------- here you create GC
                          gc.setForeground(emptyColor);
                          gc.fillRectangle(1, 1, canvas.getSize().x - 2, canvas.getSize().y - 2);
                          // resolution.setText("");
                          resolution.setVisible(false);
      
                          if (file != null) {                                                <-------------------------- here you check condition
                              Cursor parentCursor = getShell().getCursor();
                              final Cursor waitCursor = new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT);
                              Point previewPoint = new Point(0, 0);
                              Point labelPoint = canvas.getSize();
                              InputStream stream = null;
      
                              try {
                                  getShell().setCursor(waitCursor);
                                  stream = new FileInputStream(file.getLocation().toOSString());
      
                                  ImageData imageData = new ImageData(stream);
                                  stream.close();
      
                                  if (imageData != null) {
                                      Image image = new Image(getShell().getDisplay(), imageData);
      
                                      // set image in center
                                      Point imagePoint = new Point(image.getBounds().width,
                                              image.getBounds().height);
      
                                      String imageInfo = imagePoint.x + " x " + imagePoint.y + " px"; //$NON-NLS-1$ //$NON-NLS-2$
      
                                      // change resolution if image anymore image label
                                      if ((imagePoint.x > labelPoint.x) || (imagePoint.y > labelPoint.y)) {
                                          float ratioImage = (float) imagePoint.x / (float) imagePoint.y;
      
                                          if (((imagePoint.y > labelPoint.y) &&
                                                  ((labelPoint.y * ratioImage) > labelPoint.x)) ||
                                                  ((imagePoint.x > labelPoint.x) &&
                                                  ((labelPoint.x / ratioImage) < labelPoint.y))) {
                                              imageData = imageData.scaledTo(labelPoint.x - 10,
                                                      (int) (labelPoint.x / ratioImage));
                                          } else {
                                              imageData = imageData.scaledTo((int) (labelPoint.y * ratioImage) -
                                                      10, labelPoint.y);
                                          }
      
                                          image.dispose();
                                          image = new Image(getShell().getDisplay(), imageData);
                                          imagePoint.x = image.getBounds().width;
                                          imagePoint.y = image.getBounds().height;
                                      }
      
                                      previewPoint.x = (labelPoint.x / 2) - (imagePoint.x / 2);
                                      previewPoint.y = (labelPoint.y / 2) - (imagePoint.y / 2);
                                      gc.drawImage(image, previewPoint.x, previewPoint.y);
                                      resolution.setVisible(true);
                                      resolution.setText(imageInfo);
                                      image.dispose();
                                      gc.dispose();                                   <-------------------------- here you dispose
                                  }
                              } catch (IOException ev) {
                                  //ignore
                              } catch (SWTException ex) {
                                  //ignore (if select not image file) 
                              } finally {
                                  getShell().setCursor(parentCursor);
      
                                  if (stream != null) {
                                      try {
                                          stream.close();
                                      } catch (IOException e1) {
                                          // ignore
                                      }
                                  }
                              }
                          }
                      }
                  });
      

      here is absolutely invalid logic, guys
      you close the stream in two places - try to find: stream.close();
      I've check a history of changes:
      >>>
      PMD violations fixed.
      InputStreams close() added where it was possible.
      >>>
      8/29/08 - someone try to close all streams where it possible, after that all of you respect his authority and afraid to fix his error...
      btw., you are still has a problems with "close of all streams", after 8/29/08 changes...

      Attachments

        Activity

          People

            scabanovich Viacheslav Kabanovich (Inactive)
            vyemialyanchyk_jira Vitali Yemialyanchyk (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: