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

QPainter: calling save() w/o restore() causes a memory leak

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.12.2
    • Fix Version/s: 5.13.2, 5.14.0 Alpha
    • Component/s: GUI: Painting
    • Labels:
      None
    • Commits:
      b8a911fbebfcd297ce08b91fbe85bb1624d257d9 (qt/qtbase/5.13)

      Description

      QPainter::end() leaks memory, if the warning the "QPainter::end: Painter ended with %d saved states" occurs. That is, memory is leaked, if for example save() is called without calling restore() before end of painting.

      The attached example code qpainter_mem_leak.cpp reproduces the problem which was also verified with valgrind:

      valgrind --tool=memcheck --leak-check=full --track-origins=yes qpainter_mem_leak:

       

      ==24569== 2,680 (2,048 direct, 632 indirect) bytes in 2 blocks are definitely lost in loss record 3,880 of 3,913
      ==24569== at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
      ==24569== by 0x9389CD9: QRasterPaintEngine::createState(QPainterState*) const (in [...]/lib/libQt5Gui.so.5.12.2)
      ==24569== by 0x93A6244: QPainter::begin(QPaintDevice*) (in [...]/lib/libQt5Gui.so.5.12.2)

        Attachments

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

          Activity

            People

            • Assignee:
              vgt Eirik Aavitsland
              Reporter:
              andreass Andreas Schuller
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes