Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

valgrind says my code is wrong, but I don't see where ...



  • Hi,

    please apologize for not using the right technical terms.
    This is the output of valgrind:

    ==192232==  Uninitialised value was created by a heap allocation
    ==192232==    at 0x483877F: malloc (vg_replace_malloc.c:307)
    ==192232==    by 0x611782C: QArrayData::allocate(unsigned long, unsigned long, 
    unsigned long, QFlags<QArrayData::AllocationOption>) (qarraydata.cpp:218)
    ==192232==    by 0x619AF58: allocate (qarraydata.h:225)
    ==192232==    by 0x619AF58: QString::reallocData(unsigned int, bool) 
    (qstring.cpp:2371)
    ==192232==    by 0x619B057: QString::resize(int) (qstring.cpp:2288)
    ==192232==    by 0x619E972: QString::setUnicode(QChar const*, int) 
    (qstring.cpp:5687)
    ==192232==    by 0x63846CA: QTextStream::readLineInto(QString*, long long) 
    (qtextstream.cpp:1725)
    ==192232==    by 0x638498D: QTextStream::readLine(long long) (qtextstream.cpp:
    1676)
    ==192232==    by 0x199941: LcProperties::processFile(QFile&) 
    (lcproperties.cpp:124)
    ==192232==    by 0x198E35: LcProperties::LcProperties(QString const&) 
    (lcproperties.cpp:14)
    ==192232==    by 0x18BEFB: GuiKernel::initialize(QLocale const&, DBHelper&) 
    (guikernel.cpp:78)
    ==192232==    by 0x171791: Core::Core(QString const&, QString const&, QLocale 
    const&, DBHelper&, QString const&) (core.cpp:21)
    ==192232==    by 0x189855: GuiCore::GuiCore(QString const&, QString const&, 
    QLocale const&, DBHelper&, QString const&) (guicore.cpp:36)
    

    guicore.cpp:36 is the initialization call of that singleton (GuiCore is the subclass of the singletons accessor/wrapper). That call exists once in the application. Exactly at main.cpp:64

    GuiCore::setKernelCreator(new GuiKernelCreator());
    GuiCore      appCore(iniFileName, "FalconView", curLocale, dbHelper);
    

    First line creates a factory and adds it to the singleton.
    Second line calls the initialization constructor (guicore.cpp:36)

    GuiCore::GuiCore(const QString& iniFileName, const QString& appName, const 
    QLocale& locale, DBHelper& dbAssist, const QString& groupID)
     : Core(iniFileName, appName, locale, dbAssist, groupID) {
      }
    

    Second line is line 36 which valgrind blames.
    Next step is core.cpp:21 - the singletons accessor wrapper base class:

    Core::Core(const QString& iniFileName, const QString& appName, const QLocale& 
    locale, DBHelper& dbAssist, const QString& group) {
      if (!kernel) {
         assert(kc);
         kernel = kc->kernel(iniFileName, appName, group);
         kernel->initialize(locale, dbAssist);
         }
      }
    

    Line 21 is the call to initialize.
    Explaining the constructor:

    • kc is the factory set at main.
    • kernel is the static pointer of the singleton

    next blamed line is guikernel.cpp:78 - guikernel is the private class of the
    singleton static part, which extends Kernel.

    void GuiKernel::initialize(const QLocale& locale, DBHelper &dbAssist) {
      Kernel::initialize(locale, dbAssist);
      lcProps = new LcProperties(fileName);
    

    last line is line 78

    • lcProps is a member pointer (initialized to 0 at constructor call).
    • fileName is a member of superclass (Kernel) set at initialization constructor
      call from main

    constructor of LcProperties is lcproperties.cpp:14

    LcProperties::LcProperties(const QString& fileName)
     : curMap(nullptr)
     , fn(fileName) {
      QFile file(fileName);
    
      if (file.exists()) processFile(file);
      }
    

    line 14 is the call to processFile, which is next blamed line
    (lcproperties.cpp:124):

      if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
         QTextStream in(&file);
         QString line = in.readLine();
    
         while (!line.isNull()) {
               processLine(line);
               line = in.readLine();
               }
         file.close();
         }
    

    line 124 is the call to QTextStream::readLine ...

    Its a long way to here and now it dives into Qt code.
    I expect the blamed error is in the above code parts, but I don't see it.


  • Lifetime Qt Champion

    Ignore it, imo valgrind is wrong on this problem inside Qt.



  • Thanks a lot!


Log in to reply