Important: Please read the Qt Code of Conduct -

QMutex - Valgrind - Invalid read of size

  • Hi,
    I had used valgrind for test my program, and i found some "Invalid read of size" in QMutex.unlock() and QMutex.lock() .

    I wrote my own mutex for debug - for example:
    void MyMux::unlock(){
    DEBUG<<"-Unlocking "<<name <<" id:"<< QThread::currentThreadId();

    When I locking the mutex Valgrind said:
    Invalid read of size 8 in MyMutex::lock()
    Invalid read of size 4 in MyMutex::lock()
    Invalid read of size 1 in MyMutex::lock()

    Whats is wrong?

    [edit: added missing coding tags @ SGaist]

  • Moderators

    Well usually valgrind throws those type of errors when the memory for an object has been cleaned off the stack.

    It looks like you are using stack variables since you said QMutex.lock() and .unlock() rather than ->lock(), ->unlock().

    My guess is your QMutex is out of scope. If that's the case then you are just getting plain lucky on the memory and mutex working at all. But that is what valgrind is for is to catch problems like that. :)

Log in to reply