Qt / C ++ / Valgrind QTcpSocket断开连接的读取大小为8

时间:2013-10-09 05:20:33

标签: c++ qt valgrind qtcpsocket

我在我的Qt / C ++程序上运行valgrind并收到此错误:

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

和第188行是下面的waitForDisconnected行:

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

我不完全确定此错误的含义,但我该如何解决?或者这是我无法控制的? (Qt问题)?

我不确定它是否相关,但我得到的唯一其他错误是:

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

,错误行是下面的Start():

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();
}

再次......这个启动功能如何导致内存泄漏?或者“可能丢失”这个词是否意味着它确实没问题?

1 个答案:

答案 0 :(得分:0)

请参阅塞巴斯蒂安上面的评论以获得最佳答案。基本上,读/写错误是由于即使在关闭套接字后仍然继续流量到套接字(关闭不会停止所有流量)。解决方案是在删除线程时删除套接字。