Pergunta

I'm running valgrind on my Qt/C++ program and am getting this error:

Invalid read of size 8
  in TelnetConnection::disconnectClient() in telnetserver/telnetconnection.cpp:188

and line 188 is the waitForDisconnected line below:

void TelnetConnection::disconnectClient()
{
    tcpSocketPtr->disconnectFromHost();
    tcpSocketPtr->waitForDisconnected();
}

I'm not completely sure what this error means, but how can I fix this? Or is this out of my control? (a Qt issue)?

I'm not sure it's related, but the only other error I'm getting is:

384 bytes in 1 blocks are possibly lost in loss record 5,342 of 5,972
  in TelnetServer::incomingConnection(long long) in telnetserver/telnetserver.cpp:22

and the error line is Start() below:

void TelnetServer::incomingConnection(qintptr socketDescriptor)
{
    TelnetConnection *thread = new TelnetConnection(socketDescriptor, this);
    connect(thread, SIGNAL(shutdownRequested()), m_controller, SLOT(shutdownCommandIssued()));
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    connect(m_controller, SIGNAL(shutingdown()), thread, SLOT(shutdownConnection()));
    thread->start();
}

again...how can this start function cause a memory leak? Or do the words "possibly lost" mean it's actually ok?

Foi útil?

Solução

See sebastian's comments above for the best answer. Basically the read/write error is due to continued traffic to the socket even after closing the socket (close does not stop all traffic). The solution is to delete the socket on deleting the thread.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top