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

[REG] Memory leak in QJsonObject

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15, 6.3.1, 6.4.1
    • Core: Serialization
    • None
    • Linux/X11
    • Foundation PM Prioritized

    Description

      Updating a QJsonObject with a string value causes increasing memory use, the following program exhibits the problem:

      #include <QDebug>
      #include <QJsonObject>
      #include <QString>int main(int argc, char **argv) {
          QJsonObject container;    while (true) {
             container.insert("key", "value");
             qDebug() << container.size();
           }  return 0;
      }
      

      Tested on default packages on Debian and Fedora36 for 5.15 as well as 6.3 on Debian.

      5.12 does not exhibit the same problem, but as far as I can tell it doesn't use QCborContainerPrivate as the internal representation.

      The problem is that the QByteArray in container.o.d.data keeps growing; after the first loop iteration it is :

      data = "\003\000\000\000key\000\005\000\000\000value" = {
       [0] = 3 '\003',
       [1] = 0 '\000',
       [2] = 0 '\000',
       [3] = 0 '\000',
       [4] = 107 'k',
       [5] = 101 'e',
       [6] = 121 'y',
       [7] = 0 '\000',
       [8] = 5 '\005',
       [9] = 0 '\000',
       [10] = 0 '\000',
       [11] = 0 '\000',
       [12] = 118 'v',
       [13] = 97 'a',
       [14] = 108 'l',
       [15] = 117 'u',
       [16] = 101 'e'
       }

      after the second:

      data = "\003\000\000\000key\000\005\000\000\000value\000\000\000\005\000\000\000value" = {
          [0] = 3 '\003',
          [1] = 0 '\000',
          [2] = 0 '\000',
          [3] = 0 '\000',
          [4] = 107 'k',
          [5] = 101 'e',
          [6] = 121 'y',
          [7] = 0 '\000',
          [8] = 5 '\005',
          [9] = 0 '\000',
          [10] = 0 '\000',
          [11] = 0 '\000',
          [12] = 118 'v',
          [13] = 97 'a',
          [14] = 108 'l',
          [15] = 117 'u',
          [16] = 101 'e',
          [17] = 0 '\000',
          [18] = 0 '\000',
          [19] = 0 '\000',
          [20] = 5 '\005',
          [21] = 0 '\000',
          [22] = 0 '\000',
          [23] = 0 '\000',
          [24] = 118 'v',
          [25] = 97 'a',
          [26] = 108 'l',
          [27] = 117 'u',
          [28] = 101 'e'
        },
      

      Presumably there's a bug in how strings are (re)allocated in QJsonObjects. There doesn't seem to be a problem with int-types. At least I haven't seen one.

      Attachments

        Activity

          People

            thiago Thiago Macieira
            olemd Ole-Morten Duesund
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: