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. QSerialPort leaking memory?

QSerialPort leaking memory?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.6k 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.
  • mojsM Offline
    mojsM Offline
    mojs
    wrote on last edited by mojs
    #1

    My code:

    #include "gtest\gtest.h"
    
    struct CrtCheckMemory
    {
        _CrtMemState state1;
        _CrtMemState state2;
        _CrtMemState state3;
        CrtCheckMemory()
        {
            _CrtMemCheckpoint(&state1);
        }
        ~CrtCheckMemory()
        {
            _CrtMemCheckpoint(&state2);
            EXPECT_EQ(0, _CrtMemDifference(&state3, &state1, &state2));
            if (_CrtMemDifference(&state3, &state1, &state2))
                _CrtMemDumpStatistics(&state3);
        }
    };
    
    TEST(Test, testQtSerialCom)
    {
        CrtCheckMemory check;
       
        QSerialPort* port = new QSerialPort();
    
        delete port;
    
    }
    

    I'm using the Google test Framework but this should not matter at all. I get a value of 1 in _CrtMemDifference so i assume there is somehow a memory leak. Now i am confused.

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should add some background information like OS/Qt Version.

      @kuzulis Any idea about that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #3

        I have no ideas.

        Let's @mojs try to do same with the QProcess, QTcpSocket and so on, and see results.

        1 Reply Last reply
        0
        • mojsM Offline
          mojsM Offline
          mojs
          wrote on last edited by mojs
          #4

          Thx for the fast reply.

          I am using msvc2013/x64 compiler and Qt 5.5. Im not that experienced.

          I tried the same test with QTcpSocket and got the same error message. With QProcess it was a bit different:

          _CrtMemCheckpoint
          
          QProcess* proc = new QProcess();
          delete proc;
          
          _CrtMemDifference // memory leaked
          _CrtMemCheckpoint
          
          QSerialPort* port = new QSerialPort();
          delete port;
          
          _CrtMemDifference // no memory leaked
          

          I got same results when i first new/delete QSerialPort and QProcess afterwards (Then it leaked in QSerialPort but not in QProcess). I had similar problems while using parts of the boost library (boost::log) where i found out that tls variables causes this behaviour.

          As a workaround i can new/delete a QProcess before i run my tests and i get the results i want.

          1 Reply Last reply
          0

          • Login

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