Qt/C++/Valgrind 在 QTcpSocket 断开连接时读取大小为 8 无效

Qt/C++/Valgrind Invalid Readsize of 8 on QTcpSocket disconnect

本文关键字:读取 小为 无效 断开 Valgrind C++ QTcpSocket Qt 连接      更新时间:2023-10-16

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

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

而 188 行是下面的等待断开行:

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

再。。。此启动函数如何导致内存泄漏? 或者"可能丢失"这个词是否意味着它实际上没问题?

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