WaitForBytesWritten crashes



  • I've got some code that uses QTCPSocket and writes some data to it. After I write the data, I call wait for waitForBytesWritten(1000). The code runs for several seconds and then crashes. Note: I take the instance of the class and call moveToThread so perhaps threading has something to do with it.

    One of the error messages is of this form:
    malloc: *** error for object 0x101022400: pointer being freed was not allocated

    Other runs of the same code might produce this error:
    malloc: *** error for object 0x100915b10: double free

    Also note that what I'm doing is talking to a serial port over the network via ser2net. If I run this locally using QSerialPort, I have the same problem so the crash happens in QIODevice.



  • Hi RogueWarrior, why and how are you calling moveToThread() ?



  •     QThread *my_thread = new QThread;
        myIODeviceThing->moveToThread(my_thread);
        my_thread->start();
        QMetaObject::invokeMethod(myIODeviceThing, "MySlot", Qt::QueuedConnection);
    

    Followup:
    It appears that writing to the device too fast has something to do with it.
    I added an msleep(50) to the code and I haven't seen the crash. That said, it doesn't really explain the problem. Maybe there isn't proper buffer overflow protection in the QIODevice code.



  • Does your myIODeviceThing object has a parent? If it has, I think you cannot move it to another thread.

    "[QObject Class Reference - moveToThread]":http://qt-project.org/doc/qt-4.8/qobject.html#moveToThread



  • Nope, no parent.



  • Mmm well there's not too much I can help you with then. Luckily, since we've been posting stuff here, this may be on the top of the forum, so more people can see it and post an answer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.