Important: Please read the 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) 
    ==192232==    by 0x619B057: QString::resize(int) (qstring.cpp:2288)
    ==192232==    by 0x619E972: QString::setUnicode(QChar const*, int) 
    ==192232==    by 0x63846CA: QTextStream::readLineInto(QString*, long long) 
    ==192232==    by 0x638498D: QTextStream::readLine(long long) (qtextstream.cpp:
    ==192232==    by 0x199941: LcProperties::processFile(QFile&) 
    ==192232==    by 0x198E35: LcProperties::LcProperties(QString const&) 
    ==192232==    by 0x18BEFB: GuiKernel::initialize(QLocale const&, DBHelper&) 
    ==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) {
         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

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

    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