Solved QSerialPort leaking memory?
-
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.
-
Hi and welcome to devnet,
You should add some background information like OS/Qt Version.
@kuzulis Any idea about that ?
-
I have no ideas.
Let's @mojs try to do same with the QProcess, QTcpSocket and so on, and see results.
-
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.