Skip to content

Fix assert failure on vnc connection init

Fabio Bas requested to merge ctrlaltca/krdc:fix_vnc into master

The vnc backend uses a mutex with QMutexLocker. When created, QMutexLocker already locks the mutex. Calling relock() without first unlocking the mutex used to work under Qt5, while it fails an assert in Qt6 (because the mutex is already locked):

(lldb) target create "krdc"
Current executable set to '/usr/bin/krdc' (x86_64).
(lldb) r
Process 30094 launched: '/usr/bin/krdc' (x86_64)
ASSERT: "!m_isLocked" in file /usr/include/qt6/QtCore/qmutex.h, line 256
Process 30094 stopped
* thread #19, name = 'VncClientThread', stop reason = signal SIGABRT
    frame #0: 0x00007ffff4e96aab libc.so.6`pthread_kill@@GLIBC_2.34 + 251
libc.so.6`pthread_kill@@GLIBC_2.34:
->  0x7ffff4e96aab <+251>: movl   %eax, %r13d
    0x7ffff4e96aae <+254>: negl   %r13d
    0x7ffff4e96ab1 <+257>: cmpl   $0xfffff000, %eax ; imm = 0xFFFFF000 
    0x7ffff4e96ab6 <+262>: movl   $0x0, %eax
(lldb) bt
* thread #19, name = 'VncClientThread', stop reason = signal SIGABRT
  * frame #0: 0x00007ffff4e96aab libc.so.6`pthread_kill@@GLIBC_2.34 + 251
    frame #1: 0x00007ffff4e42e12 libc.so.6`raise + 18
    frame #2: 0x00007ffff4e2849f libc.so.6`abort + 197
    frame #3: 0x00007ffff56c138e libQt6Core.so.6`qAbort() + 6
    frame #4: 0x00007ffff56f8505 libQt6Core.so.6`___lldb_unnamed_symbol10878 + 453
    frame #5: 0x00007ffff56c2056 libQt6Core.so.6`QMessageLogger::fatal(char const*, ...) const + 146
    frame #6: 0x00007ffff56c130c libQt6Core.so.6`qt_assert(char const*, char const*, int) + 68
    frame #7: 0x00007fffd80af92d krdc_vncplugin.so`QMutexLocker<QMutex>::relock(this=0x00007fff97ffebb0) at qmutex.h:256:9
    frame #8: 0x00007fffd80ab8e4 krdc_vncplugin.so`VncClientThread::run(this=0x0000000000b61990) at vncclientthread.cpp:522:22
    frame #9: 0x00007ffff591da77 libQt6Core.so.6`___lldb_unnamed_symbol13445 + 295
    frame #10: 0x00007ffff4e94d57 libc.so.6`start_thread + 823
    frame #11: 0x00007ffff4f196a8 libc.so.6`__clone3 + 40

This PR is trivial, it unlocks the mutex before the relock()

Merge request reports