Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Valgrind memory analyzer in Qt Creator finds a problem and then crashes Qt

Valgrind memory analyzer in Qt Creator finds a problem and then crashes Qt

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 370 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GuerrianG Offline
    GuerrianG Offline
    Guerrian
    wrote on last edited by
    #1

    I am getting a message from the Valgind memory analyzer: "32,816 bytes in 1 blocks are definitely lost..."

    The function and line number where this is occurring:

    void processDir(string dn)
    {
        DIR *dir;
        dirent *pdir;
        vector<string> fls;
        vector<string>::size_type v, sz;
        string str;
        dir = opendir(dn.c_str()); // <- problem reported here
        if (dir == NULL)
            cout << "bad directory" << endl;
        else
        {
            while ((pdir = readdir(dir)) != NULL)
            {
                str = pdir->d_name;
                if (str != "." && str != ".." && str != "README.txt")
                    fls.push_back(str);
            }
            sz = fls.size();
            if (sz > MAX_FILES)
            {
                cout << "too many files, limit is " << MAX_FILES << endl;
                return;
            }
            sort(fls.begin(), fls.end());
            for(v = 0; v < sz; v++)
                processFile(dn + "/" + fls[v]);
        }
    }
    

    If I click on the message then Qt Creator crashes with no further error message.

    Should I be using QString instead of std::string?

    I'm using Qt Creator 3.5.1 on Linux Mint 18.3.

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

    aha_1980A 1 Reply Last reply
    0
    • GuerrianG Guerrian

      I am getting a message from the Valgind memory analyzer: "32,816 bytes in 1 blocks are definitely lost..."

      The function and line number where this is occurring:

      void processDir(string dn)
      {
          DIR *dir;
          dirent *pdir;
          vector<string> fls;
          vector<string>::size_type v, sz;
          string str;
          dir = opendir(dn.c_str()); // <- problem reported here
          if (dir == NULL)
              cout << "bad directory" << endl;
          else
          {
              while ((pdir = readdir(dir)) != NULL)
              {
                  str = pdir->d_name;
                  if (str != "." && str != ".." && str != "README.txt")
                      fls.push_back(str);
              }
              sz = fls.size();
              if (sz > MAX_FILES)
              {
                  cout << "too many files, limit is " << MAX_FILES << endl;
                  return;
              }
              sort(fls.begin(), fls.end());
              for(v = 0; v < sz; v++)
                  processFile(dn + "/" + fls[v]);
          }
      }
      

      If I click on the message then Qt Creator crashes with no further error message.

      Should I be using QString instead of std::string?

      I'm using Qt Creator 3.5.1 on Linux Mint 18.3.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Guerrian said in Valgrind memory analyzer in Qt Creator finds a problem and then crashes Qt:

      DIR *dir;

      I think this is the problem. Have you tried adding closedir at the end of your function?

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • GuerrianG Offline
        GuerrianG Offline
        Guerrian
        wrote on last edited by Guerrian
        #3

        Yeah, adding "closedir(dir)" gets rid of the problem. It makes sense, thanks.

        Linux Mint 18.3
        Qt 5.14.1
        Qt Creator 4.11.1

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved