QtAbstractSocket -> Debug Assertion Failed: _BLOCK_TYPE_IS_VALID( pHead->nBlockUse )



  • Hallo,

    ich habe gerade das Problem das meine Qt 5.0.2 MSVC2012 TCPClient Anwendung im Debug-Modus (auch Release) mit dem Fehler:

    File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
    Line: 52
    
    Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
    Debug Assertion Failed: _BLOCK_TYPE_IS_VALID( pHead->nBlockUse )
    

    Abstürzt.

    Was mache ich konkret:
    -> ConnectToHost
    -> Handshake Paket senden
    -> Handshake empfangen -> Besagter Fehler

    Genau genommen passiert es im folgenden Auszug der readPackage() Methode:

    short cReadSize = 0;
    TCPHandshake socketData; // Paketstruktur
    short cSize       = sizeof(socketData) - cReadSize;
    char* readBuffer  = (char*) malloc(cSize);
    uint64 cReadType  = socket->read(readBuffer, cSize); // Hier Passiert der Absturz
    
    if(cReadType == -1 || cReadType == 0 || cReadType != cSize)
       throw Error(tr("Read error! Readsize %1/%2").arg(cReadType).arg(cSize));  
    
    memcpy((char *)&socketData + cReadSize, readBuffer, cSize); // Um nByte verschieben da wie ja bereits Daten aus dem Stream für das struct gelesen haben
    cReadSize   += cSize;
    free(readBuffer);
    

    Es sollen 24 Byte gelesen werden, es sind auch noch 24 Byte im Socket vorhanden.
    Kurios ist wenn ich cSize im Debugger auf 23 abändere, wird der Socket ausgelesen.
    Allerdings fehlt mir dann ein Byte.

    Client Methoden:

    void TCPConnector::Init(QString address, uint16 nPort, uint32 nTimeout, uint16 nMaxRetry, bool saveEnergy, bool compressionAvailable, TCPSyntax syntax) {
    
       this->socket_                 = new QTcpSocket();
       this->tcpbase_                = new TCPBase();
       this->address_                = address;
       this->nPort_                  = nPort;
       this->nTimeout_               = nTimeout;
       this->nMaxRetry_              = nMaxRetry;
       this->nCntRetry_              = 0;
       this->syntax_                 = syntax;
    
       this->tcpbase_->setCompressionAvailable(compressionAvailable);
       this->tcpbase_->saveEnergy(saveEnergy);
       this->tcpbase_->setHandshaking(false);
    
       connect(this->socket_, SIGNAL(disconnected())      , this, SLOT(HostClosedConnection()));
       connect(this->socket_, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(HandleSocketError(QAbstractSocket::SocketError)));
    
       this->ConnectToHost();
    }
    
    void TCPConnector::ConnectToHost(){
    
       qDebug() << "Try to connect to host " << this->address_ << ":" << this->nPort_;
       this->socket_->abort();
       this->socket_->connectToHost(QHostAddress(this->address_), this->nPort_);
    
          qDebug() << "initialize handshaking";
    		if(this->socket_->waitForConnected(this->nTimeout_)){
    
             // Handshake an den Server senden       
             {
                qDebug() << "> send handshake";
                TCPPacket request;
                uint32                                          ulFlag  = TCPHandshakeFlag::TX_CONNECTION;
                if (this->tcpbase_->isCompressionAvailable())   ulFlag |= TCPHandshakeFlag::COMPRESSION_AVAILABLE;
                if (this->tcpbase_->isSaveEnergy())             ulFlag |= TCPHandshakeFlag::SAVEENERGY;
    
                request.setHandshake(this->syntax_, ulFlag, 100,200,300,400);
                this->tcpbase_->sendPackage(this->socket_, request, TCPIP_MAGICBYTE_HANDSHAKE);
    
                // Antwort (Handshake) empfangen
                qDebug() << "> recieve handshake";
                TCPPacket reply;
    		      if(this->socket_->waitForReadyRead()){
                   this->tcpbase_->readPackage(this->socket_, reply, false);
    
                   TCPHandshake handshake = reply.getHandshake();
                   this->tcpbase_->setHandshaking(true);
                   this->tcpbase_->setHandshakingHandle(handshake.extra1);
                }
             }
    
             // Nutzdaten uebertragen  
             if(this->tcpbase_->hasHandshaking()) {
                TCPPacket request;
                qDebug() << "> send data";
                this->tcpbase_->sendContent(this->socket_, request, "<handshake><version>1.0.0</version>\n<device>DESKTOP</device>\n<imei>0000000000000000</imei>\n<mac>00:AA:BB:CC:DD:EE</mac>\n</handshake>");
    
                // Antwort empfangen
                TCPPacket reply;
                qDebug() << "> recieve data";
                if(this->socket_->waitForReadyRead()){
                   this->tcpbase_->readPackage(this->socket_, reply, this->tcpbase_->hasHandshaking());
    
                   TCPHeader header = reply.getHeader();
    
                }
             }
          }
    
    	if(this->socket_->state() != QAbstractSocket::SocketState::UnconnectedState){
    		this->socket_->close();
    	}
    
    }
    


  • Ich habe heute die Anwendung mit Dr Memory durchlaufen lassen.

    Hier läuft die Anwendung natürlich durch...

    Hier der Log:

    Try to connect to host  "192.168.73.34" : 20 
    
             Error #35: UNINITIALIZED READ: reading 9 byte(s)
             system call NtCreateFile parameter #9
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!WSASocketW
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::hostFound
                 ??:0
             Qt5Network.dll!operator<<    
                 ??:0
             Qt5Network.dll!operator<<    
                 ??:0
             Qt5Network.dll!QAbstractSocket::connectToHost
                 ??:0
             Qt5Network.dll!QAbstractSocket::connectToHost
                 ??:0
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(41):
    initialize handshaking 
    
             Error #36: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!select    
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::waitForConnected
                 ??:0
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(46):
             tcpdingens.shared.dll!TCPConnector::Init  
                 tcpconnector.cpp(34):
             tcpdingens.shared.dll!TCPConnector::TCPConnector
                 tcpconnector.cpp(5):
             tcpdingens.core.dll!tcpdingensServer::initialize
                 tcpdingensserver.cpp(266):
             tcpdingens.core.dll!ServerApp::run    
                 serverapp.cpp(154):
    
    > send handshake 
    SEND.......: HANDSHAKE  28  Bytes 
    MagicByte..: 1213744384 
    
             Error #37: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!select    
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::waitForBytesWritten
                 ??:0
             tcpdingens.shared.dll!TCPBase::WriteData  
                 tcpbase.cpp(286):
             tcpdingens.shared.dll!TCPBase::sendPackage
                 tcpbase.cpp(212):
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(63):
             tcpdingens.shared.dll!TCPConnector::Init  
                 tcpconnector.cpp(34):
             tcpdingens.shared.dll!TCPConnector::TCPConnector
                 tcpconnector.cpp(5):
             tcpdingens.core.dll!tcpdingensServer::initialize
                 tcpdingensserver.cpp(266):
    > recieve handshake 
    
             Error #38: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!select    
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::waitForReadyRead
                 ??:0
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(69):
             tcpdingens.shared.dll!TCPConnector::Init  
                 tcpconnector.cpp(34):
             tcpdingens.shared.dll!TCPConnector::TCPConnector
                 tcpconnector.cpp(5):
             tcpdingens.core.dll!tcpdingensServer::initialize
                 tcpdingensserver.cpp(266):
             tcpdingens.core.dll!ServerApp::run    
                 serverapp.cpp(154):
    
    RECIEVE....: MAGICBYTE  4  Byte 
    MagicByte..: 1213744384 
    
    RECIEVE....: HANDSHAKE  24  Byte 
    MagicByte..: 1213744384 
    
    > send data 
    SEND.......: HEADER  16  Bytes 
    MagicByte..: 1347962112 
    Nutzdaten..: JA  165  Byte 
    
             Error #39: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!select    
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::waitForBytesWritten
                 ??:0
             tcpdingens.shared.dll!TCPBase::WriteData  
                 tcpbase.cpp(286):
             tcpdingens.shared.dll!TCPBase::sendPackage
                 tcpbase.cpp(264):
             tcpdingens.shared.dll!TCPBase::sendContent
                 tcpbase.cpp(173):
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(85):
             tcpdingens.shared.dll!TCPConnector::Init  
                 tcpconnector.cpp(34):
             tcpdingens.shared.dll!TCPConnector::TCPConnector
                 tcpconnector.cpp(5):
    > recieve data 
    
             Error #40: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!?          
                 ??:0
             WS2_32.dll!select    
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QLocalServer::waitForNewConnection
                 ??:0
             Qt5Network.dll!QAbstractSocket::waitForReadyRead
                 ??:0
             tcpdingens.shared.dll!TCPConnector::ConnectToHost
                 tcpconnector.cpp(90):
             tcpdingens.shared.dll!TCPConnector::Init  
                 tcpconnector.cpp(34):
             tcpdingens.shared.dll!TCPConnector::TCPConnector
                 tcpconnector.cpp(5):
             tcpdingens.core.dll!tcpdingensServer::initialize
                 tcpdingensserver.cpp(266):
             tcpdingens.core.dll!ServerApp::run    
                 serverapp.cpp(154):
    
    RECIEVE....: MAGICBYTE  4  Byte 
    MagicByte..: 1347962112 
    
    RECIEVE....: HEADER  16  Byte 
    MagicByte..: 1347962112 
    Nutzdaten..: 
     "
    <message>
    	<handshake>
    		<ok/>
    	</handshake>
    </message>" 
    
    Host closed connection! 
    
             Error #41: UNINITIALIZED READ: reading 3 byte(s)
             system call NtDeviceIoControlFile AFD_POLL_INFO pre-Handles
                 <system call>
             MSWSOCK.dll!getnetbyname
                 ??:0
             MSWSOCK.dll!getnetbyname
                 ??:0
             MSWSOCK.dll!?          
                 ??:0
             MSWSOCK.dll!?          
                 ??:0
             KERNEL32.dll!BaseThreadInitThunk
                 ??:0
             ntdll.dll!RtlInitializeExceptionChain
                 ??:0
             ntdll.dll!RtlInitializeExceptionChain
                 ??:0
             MSWSOCK.dll!?          
                 ??:0
             MSWSOCK.dll!?          
                 ??:0
    
             Error #42: UNINITIALIZED READ: reading 16 byte(s)
             system call NtRequestPort
                 <system call>
             ntdll.dll!RtlRegisterThreadWithCsrss
                 ??:0
             ntdll.dll!RtlRegisterThreadWithCsrss
                 ??:0
             KERNEL32.dll!BaseThreadInitThunk
                 ??:0
             ntdll.dll!RtlInitializeExceptionChain
                 ??:0
             ntdll.dll!RtlInitializeExceptionChain
                 ??:0
    


  • Keiner eine Idee?

    Ich habe mal weiter geforscht, in der qiodevice.cpp bleibt er hängen.

    qint64 QIODevice::read(char *data, qint64 maxSize)
    {
        Q_D(QIODevice);
    
    #if defined QIODEVICE_DEBUG
        printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n",
               this, data, int(maxSize), int(d->pos), int(d->buffer.size()));
    #endif
    
        // Short circuit for getChar()
        if (maxSize == 1) {
            int chint;
            while ((chint = d->buffer.getChar()) != -1) {
                ++(*d->pPos);
    
                char c = char(uchar(chint));
                if (c == '\r' && (d->openMode & Text))
                    continue;
                *data = c;
    #if defined QIODEVICE_DEBUG
                printf("%p \tread 0x%hhx (%c) returning 1 (shortcut)\n", this,
                       int(c), isprint(c) ? c : '?');
    #endif
                if (d->buffer.isEmpty())
                    readData(data, 0);
                return qint64(1);
            }
        }
    
        CHECK_MAXLEN(read, qint64(-1));
        qint64 readSoFar = 0;
        bool moreToRead = true;
        do {
            // Try reading from the buffer.
            int lastReadChunkSize = d->buffer.read(data, maxSize);
            if (lastReadChunkSize > 0) {
                *d->pPos += lastReadChunkSize;
                readSoFar += lastReadChunkSize;
                // fast exit when satisfied by buffer
                if (lastReadChunkSize == maxSize && !(d->openMode & Text)) {
                    if (d->buffer.isEmpty()) {
                        d->buffer.clear();  // Absturz
                        readData(data, 0);
                    }
                    return readSoFar;
                }
    

    In der Variable buff steht folgendes "0x00495620" "HXE"

    class QIODevicePrivateLinearBuffer
    {
    public:
        QIODevicePrivateLinearBuffer(int) : len(0), first(0), buf(0), capacity(0) {
        }
        ~QIODevicePrivateLinearBuffer() {
            delete [] buf;
        }
        void clear() {
            len = 0;
            delete [] buf; // <- Hier
            buf = 0;
            first = buf;
            capacity = 0;
        }
    

Log in to reply