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

Memory leak using QAssociativeIterable::value()

    XMLWordPrintable

    Details

    • Commits:
      d7fa2d060a58b0e79d7df84a4fc54f44de9b2610

      Description

      In the implementation of QAssociativeIterable::value it is necessary to call destroyIter on the impl object and the endIt object when they are no longer needed. Otherwise, the iterators leak:

      #include <QCoreApplication>
      #include <QDebug>
      #include <QVariant>
      
      int main(int argc, char** argv)
      {
          QCoreApplication app(argc, argv);
      
          QVariant var;
          QVariantHash hash;
          hash.insert("Foo", 45);
          var = hash;
          QAssociativeIterable iter = var.value<QAssociativeIterable>();
          qDebug() << iter.value("Foo");
       
          return 0;
      }
      
      $ valgrind --leak-check=full ./main 
      ==15190== Memcheck, a memory error detector
      ==15190== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
      ==15190== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
      ==15190== Command: ./main
      ==15190== 
      QVariant(int, 45)
      ==15190== 
      ==15190== HEAP SUMMARY:
      ==15190==     in use at exit: 3,860 bytes in 34 blocks
      ==15190==   total heap usage: 187 allocs, 153 frees, 19,091 bytes allocated
      ==15190== 
      ==15190== 8 bytes in 1 blocks are definitely lost in loss record 5 of 34
      ==15190==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==15190==    by 0x403D57: void QtMetaTypePrivate::QAssociativeIterableImpl::findImpl<QHash<QString, QVariant> >(void const*, void const*, void**) (in /home/stephen/safe/dev/playground/memleak/build/main)
      ==15190==    by 0x51CBF6A: QtMetaTypePrivate::QAssociativeIterableImpl::find(QtMetaTypePrivate::VariantData const&) (qmetatype.h:1208)
      ==15190==    by 0x51BA0DC: QAssociativeIterable::value(QVariant const&) const (qvariant.cpp:3882)
      ==15190==    by 0x403070: main (in /home/stephen/safe/dev/playground/memleak/build/main)
      ==15190== 
      ==15190== 8 bytes in 1 blocks are definitely lost in loss record 6 of 34
      ==15190==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==15190==    by 0x4037DD: void QtMetaTypePrivate::QAssociativeIterableImpl::endImpl<QHash<QString, QVariant> >(void const*, void**) (in /home/stephen/safe/dev/playground/memleak/build/main)
      ==15190==    by 0x51CBE36: QtMetaTypePrivate::QAssociativeIterableImpl::end() (qmetatype.h:1198)
      ==15190==    by 0x51BA15E: QAssociativeIterable::value(QVariant const&) const (qvariant.cpp:3884)
      ==15190==    by 0x403070: main (in /home/stephen/safe/dev/playground/memleak/build/main)
      ==15190== 
      ==15190== LEAK SUMMARY:
      ==15190==    definitely lost: 16 bytes in 2 blocks
      ==15190==    indirectly lost: 0 bytes in 0 blocks
      ==15190==      possibly lost: 0 bytes in 0 blocks
      ==15190==    still reachable: 3,844 bytes in 32 blocks
      ==15190==         suppressed: 0 bytes in 0 blocks
      ==15190== Reachable blocks (those to which a pointer was found) are not shown.
      ==15190== To see them, rerun with: --leak-check=full --show-leak-kinds=all
      ==15190== 
      ==15190== For counts of detected and suppressed errors, rerun with: -v
      ==15190== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
      

        Attachments

        For Gerrit Dashboard: QTBUG-41469
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            mmutz Marc Mutz
            Reporter:
            steveire Stephen Kelly (Personal)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes