The patch below is a hack that makes qgis build on aarch64.  It's
not the correct fix.

What happens is that the destructor of the QWaitCondition class is
called more than once. The second time it is called from Python's atexit
handler crashes due to a use-after-free in pthread_cond_destroy().

The patch below simply avoids this.  The correct fix would have to root
cause why this happens on aarch64 and not on amd64.

The backtrace looks something like this:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  pthread_cond_destroy (condp=0x8) at 
/usr/src/lib/libc/thread/rthread_cond.c:54
54              cond = *condp;
(gdb) bt
#0  pthread_cond_destroy (condp=0x8) at 
/usr/src/lib/libc/thread/rthread_cond.c:54
#1  0x00000017eee75c94 in QWaitCondition::~QWaitCondition() ()
   from /usr/local/lib/qt5/libQt5Core.so.3.0
#2  0x000000187be1cbf0 in _libc___cxa_finalize (dso=0x0) at 
/usr/src/lib/libc/stdlib/atexit.c:177
#3  0x000000187be04f60 in _libc_exit (status=0) at 
/usr/src/lib/libc/stdlib/exit.c:54
#4  0x000000184b7b79cc in Py_Exit () from /usr/local/lib/libpython3.9.so.0.0
#5  0x000000184b7bd0d0 in _PyErr_PrintEx () from 
/usr/local/lib/libpython3.9.so.0.0
#6  0x000000184b7bbdfc in PyRun_SimpleFileExFlags () from 
/usr/local/lib/libpython3.9.so.0.0
#7  0x000000184b7e0bec in Py_RunMain () from /usr/local/lib/libpython3.9.so.0.0
#8  0x000000184b7e1bdc in pymain_main () from /usr/local/lib/libpython3.9.so.0.0
#9  0x000000184b7e1ed8 in Py_BytesMain () from 
/usr/local/lib/libpython3.9.so.0.0
#10 0x00000013a6600860 in _start ()

Index: Makefile
===================================================================
RCS file: /cvs/ports/x11/qt5/qtbase/Makefile,v
retrieving revision 1.52
diff -u -p -r1.52 Makefile
--- Makefile    11 Mar 2022 20:16:59 -0000      1.52
+++ Makefile    17 Jun 2022 07:47:27 -0000
@@ -7,7 +7,7 @@ COMMENT-mysql =         MySQL plugin for Qt5
 COMMENT-psql =         PostgresSQL plugin for Qt5
 COMMENT-tds =          TDS plugin for Qt5
 
-REVISION-main =                9
+REVISION-main =                10
 REVISION-examples =    0
 
 PKGNAME-mysql =                qt5-mysql-${VERSION}
Index: patches/patch-src_corelib_thread_qwaitcondition_unix_cpp
===================================================================
RCS file: patches/patch-src_corelib_thread_qwaitcondition_unix_cpp
diff -N patches/patch-src_corelib_thread_qwaitcondition_unix_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_corelib_thread_qwaitcondition_unix_cpp    17 Jun 2022 
06:46:24 -0000
@@ -0,0 +1,16 @@
+Index: src/corelib/thread/qwaitcondition_unix.cpp
+--- src/corelib/thread/qwaitcondition_unix.cpp.orig
++++ src/corelib/thread/qwaitcondition_unix.cpp
+@@ -181,9 +181,12 @@ QWaitCondition::QWaitCondition()
+ 
+ QWaitCondition::~QWaitCondition()
+ {
++    if (d == nullptr)
++        return;
+     report_error(pthread_cond_destroy(&d->cond), "QWaitCondition", "cv 
destroy");
+     report_error(pthread_mutex_destroy(&d->mutex), "QWaitCondition", "mutex 
destroy");
+     delete d;
++    d = nullptr;
+ }
+ 
+ void QWaitCondition::wakeOne()

Reply via email to