[Development] QTBUG-48709: calling ::exit() may crash

Sergio Martins sergio.martins at kdab.com
Wed Oct 21 13:34:25 CEST 2015


On Wednesday, October 21, 2015 03:15:38 AM Robert Griebl wrote:
> On 20.10.2015 17:56, Thiago Macieira wrote:
> > ...because the application will unload the libraries while other threads
> > are still running code from those threads. In the bug report, the crash
> > happens because of the QXcbEventReader thread, but it could have been any
> > other thread we start or any other library starts.
> > 
> > Can anyone think of a solution to this problem?
> 
> We had the exact some problem with Wayland a few weeks ago, where
> QtWayland would call ::exit() if it encounters an error: the process
> would then crash while trying to cleanup a sqlite database. 

I had that too, but it's a different bug. It happens on the same thread that 
called exit().

libQt5Sql.so calls plugin code at static dtor time, at which point the plugin 
was already unloaded.

 Access not within mapped region at address 0x7146D60
   at 0x6AE6F86: QSqlDatabase::close() (qsqldatabase.cpp:871)
   by 0x6AE6D58: QSqlDatabase::~QSqlDatabase() (qsqldatabase.cpp:799)
   by 0x6AE9F0D: QHashNode<QString, QSqlDatabase>::~QHashNode() (qhash.h:197)
   by 0x6AE9F41: QHash<QString, QSqlDatabase>::deleteNode2(QHashData::Node*) 
(qhash.h:545)
   by 0x6CBB5A1: QHashData::free_helper(void (*)(QHashData::Node*)) 
(qhash.cpp:493)
   by 0x6AE97A8: QHash<QString, QSqlDatabase>::freeData(QHashData*) (qhash.h:
581)
   by 0x6AE890F: QHash<QString, QSqlDatabase>::~QHash() (in /data/
installation/qt/x86_64-foo-5.4d/lib/libQt5Sql.so.5.4.3)
   by 0x6AE8575: QConnectionDict::~QConnectionDict() (qsqldatabase.cpp:110)
   by 0x6AE5AC9: (anonymous 
namespace)::Q_QGS_dbDict::innerFunction()::Holder::~Holder() 
(qsqldatabase.cpp:126)
   by 0x7A5CF87: __run_exit_handlers (in /usr/lib/libc-2.22.so)
   by 0x7A5CFD4: exit (in /usr/lib/libc-2.22.so)
   by 0xBFD15E3: QWaylandDisplay::exitWithError() (qwaylanddisplay.cpp:193)


Inspecting where the unmapped 0x7146D60 is:

0x0000000007146a20 - 0x0000000007146dd8 is .data.rel.ro in /data/installation/
qt/x86_64-foo-5.4d/plugins/sqldrivers/libqsqlpsql.so


So:

1) Don't have code running at static cleanup time, unless you have to.

2) If you have to do 1) then don't call code of libraries you don't link 
against, unless you have to. ( plugin calling libQt5Sql is fine, the other way 
is not).

3) If you have to do 2), then don't call exit() :)

Regards,
-- 
SĂ©rgio Martins | sergio.martins at kdab.com | Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt Experts



More information about the Development mailing list