Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-41322

Leak in GraphicsView: Destructor Missing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.3.1
    • Widgets: GraphicsView
    • None
    • Windows 7 with Custom built Qt 5.3.1 with OpenGL.

    Description

      The Private Classes QGraphicsGridLayoutPrivate and QGraphicsLinearLayoutPrivate are without any Destructor. This can lead to a high amount of Memory Leaks when dealing with dynamic widgets, removing and adding them on the fly. It should also happen when dealing with static user interfaces.

      The problem is that styleInfo() creates a QGraphics*StyleInfo Object which will never be removed from the heap anymore.

      To solve this these private classes need to have a destructor which deletes m_styleInfo (delete on NULL pointer is valid as well).

      Suggestion:

      qgraphicsgridlayout.cpp:

      [...]
      class QGraphicsGridLayoutPrivate : public QGraphicsLayoutPrivate
      {
      public:
          QGraphicsGridLayoutPrivate(): m_styleInfo(0) { }
          ~QGraphicsGridLayoutPrivate() { delete m_styleInfo; }  // <<-- this line fixes the memory problem
          QGraphicsLayoutStyleInfo *styleInfo() const;
      
          mutable QGraphicsLayoutStyleInfo *m_styleInfo;
          QGraphicsGridLayoutEngine engine;
      
      #ifdef QGRIDLAYOUTENGINE_DEBUG
          void dump(int indent) const;
      #endif
      };
      [...]
      
      qgraphicslinearlayout.cpp:
      [...]
      class QGraphicsLinearLayoutPrivate : public QGraphicsLayoutPrivate
      {
      public:
          QGraphicsLinearLayoutPrivate(Qt::Orientation orientation)
              : orientation(orientation),
                m_styleInfo(0)
          { }
          ~QGraphicsLinearLayoutPrivate() { delete m_styleInfo; } // this line fixes the memory problem
      
          void removeGridItem(QGridLayoutItem *gridItem);
          QGraphicsLayoutStyleInfo *styleInfo() const;
          void fixIndex(int *index) const;
          int gridRow(int index) const;
          int gridColumn(int index) const;
      
          Qt::Orientation orientation;
          mutable QGraphicsLayoutStyleInfo *m_styleInfo;
          QGraphicsGridLayoutEngine engine;
      };
      [...]
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              peppe Giuseppe D'Angelo
              roalter Luis Roalter
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes