PDA

View Full Version : conditional jump or move depends on uninitialised value(s) libQtNetwork.so.4.7.4



migel
2nd March 2012, 11:11
I am analyzing my code using valgrind tool for QtCreator and there is some leak which I don't understand and I am assuming this is coming from QT and not from my code.


Conditional jump or move depends on uninitialised value(s)
in Test::Test(QNetworkReply*, Test::CallType) in respond.cpp:16
1: /usr/lib64/qt4/libQtNetwork.so.4.7.4
2: QIODevice::read(char*, long long) in /usr/lib64/qt4/libQtCore.so.4.7.4
3: QIODevice::readAll() in /usr/lib64/qt4/libQtCore.so.4.7.4
4: Test::Test(QNetworkReply*, Test::CallType) in <a href="file:///home/me/workspace/desktop/Desktop/respond.cpp:16" >respond.cpp:16</a>
.
.
.


My Test construct class ...in short... looks like this:


Test::Test(QNetworkReply *reply)
{
if(reply)
{
QByteArray data = reply->readAll(); <<<<<< line 16
reply->deleteLater();
}
}

Thanks for looking.

high_flyer
2nd March 2012, 11:30
My guess is that valgrind is seeing a leak here, since you are using deleteLater(), which means you are not delete the reply object your self.
Are you running the valgrid session to the end (that is, so that the application finishes) or do you break the application at some point?

migel
2nd March 2012, 12:34
Test class is a part of another thread which running in the QTimer loop. I let the app run for a while then quit it normally, closing threads and the app. But the logs appearing during the run time.

Added after 10 minutes:

I have tried delete the reply just for testing which is not safe to do it.
Same error.

high_flyer
2nd March 2012, 12:42
I think this is a false positive.
To make sure you can try deleting the reply object in the thread it was created in. (just as a test, your code is the correct way to do it with deleteLater()).

migel
2nd March 2012, 12:51
yeah, I tried delete reply. Did not help.

wysota
2nd March 2012, 13:29
Can you show us the definition of your Test class?

migel
2nd March 2012, 13:52
sure

There is one more error in this class in line 32


Conditional jump or move depends on uninitialised value(s)
in Test::Codes(int const&amp;) in test.cpp:32
1: Test::Codes(int const&amp;) in test.cpp:32
2: Test::VerifyTest() in test.cpp:44

the header

#include <QNetworkReply>

class Test
{

public:

Test();
Test(QNetworkReply *reply);
const QByteArray Data() const;
int Code() const;
bool IsSuccess() const;
bool IsError() const;

private:

void VerifyTest();
bool Codes(const int &code);

QByteArray _respondData;
QString _respondError;
int _respondCode;
bool _success;
QString _respondUrl;
};



the source

#include "test.h"

Test::Test() :
_respondData(""), _respondError(""), _respondCode(0), _success(false), _respondUrl("")
{
}

Test::Test(QNetworkReply *reply) :
_respondData(""), _respondError(""), _respondCode(0), _success(false), _respondUrl("")
{
if(reply)
{
_respondData = reply->readAll(); << line 16
_respondError = reply->errorString();
_respondCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute).toInt();
_respondUrl = reply->url().toString();

VerifyTest();
reply->deleteLater();
}
}

bool Test::Codes(const int &code)
{
switch( code ) << line 32
{
case 200:
return true;
default:
return false;
}
}

void Test::VerifyTest()
{
if (Codes(_respondCode)) << line 44
{
_success = true;
}
else
{
// false ...
}
}

const QByteArray Test::Data() const
{
return _respondData;
}

int Test::Code() const
{
return _respondCode;
}

bool Test::IsSuccess() const
{
return _success;
}

bool Test::IsError() const
{
return !_success;
}


Added after 5 minutes:

You will notice line 16 is different.

_respondData = reply->readAll(); << line 16

But the error remains when I change to

QByteArray respondData = reply->readAll(); << line 16

wysota
2nd March 2012, 14:00
Is this your actual code? Because the error message claims the constructor takes two parameters while in your code it has only one parameter. Does the error go away if you add it?

migel
2nd March 2012, 14:44
I have removed Test::CallType this is the enum param and its not the case.