Bug 373779 - QFileDialog integration causes crashes on program exit
Summary: QFileDialog integration causes crashes on program exit
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 5.29.0
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-17 18:07 UTC by David Korth
Modified: 2018-08-22 20:41 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Korth 2016-12-17 18:07:52 UTC
In a pure Qt application, if a QFileDialog is used to open a file, the program will crash when it exits. If the user cancels the QFileDialog, the crash won't happen.

Test case:

#include <QApplication>
#include <QFileDialog>

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QString filename = QFileDialog::getOpenFileName(nullptr, "Select File");
	printf("file == %s\n", filename.toUtf8().constData());
}

Compile with:
gcc getOpenFileName-test.cpp -O getOpenFileName-test -fpic -fPIC -I /usr/include/qt5/QtWidgets -I /usr/include/qt5 -lQt5Widgets -lQt5Gui -lQt5Core

GDB backtrace:
Thread 1 "getOpenFileName" received signal SIGSEGV, Segmentation fault.
0x00007ffff6fe9bc4 in QHash<QRegExpEngineKey, QCache<QRegExpEngineKey, QRegExpEngine>::Node>::deleteNode2(QHashData::Node*) () from /usr/lib64/libQt5Core.so.5
(gdb) bt
#0  0x00007ffff6fe9bc4 in QHash<QRegExpEngineKey, QCache<QRegExpEngineKey, QRegExpEngine>::Node>::deleteNode2(QHashData::Node*) () from /usr/lib64/libQt5Core.so.5
#1  0x00007ffff70ae7a9 in QHashData::free_helper(void (*)(QHashData::Node*)) () from /usr/lib64/libQt5Core.so.5
#2  0x00007ffff6ff466c in (anonymous namespace)::Q_QGS_globalEngineCache::innerFunction()::Holder::~Holder() () from /usr/lib64/libQt5Core.so.5
#3  0x00007ffff62c2a80 in __run_exit_handlers (status=0, listp=0x7ffff66235b8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, 
    run_dtors=run_dtors@entry=true) at exit.c:83
#4  0x00007ffff62c2ada in __GI_exit (status=<optimized out>) at exit.c:105
#5  0x00007ffff62ad2a8 in __libc_start_main (main=0x400be6 <main>, argc=1, argv=0x7fffffffd988, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=0x7fffffffd978) at ../csu/libc-start.c:323
#6  0x0000000000400b1a in _start ()

This crash does not occur if QFileDialog::DontUseNativeDialog is set.

My system has KDE Frameworks 5.29 and KDE Applications 16.12.0.
Comment 1 Michael Pyne 2016-12-17 19:37:25 UTC
Despite the very good instructions to reproduce, I'm not able to reproduce the crash myself.

What version of Qt do you have?  There have been changes to Qt to prevent dynamic libraries from being unloaded (in QFactoryLoader, QPluginLoader already refused to unload), which might explain your crash if you have an older Qt library.

The initial patch to stop unloading of unneeded dynamic libraries was for Qt 5.8 (https://codereview.qt-project.org/#/c/140750/) but was later backported to Qt 5.6 and 5.7 (https://codereview.qt-project.org/#/c/174911/).  But I'm not sure which releases contained the fix.

If this stops the crash then it may be a similar issue to QStringLiteral crashers, where a cache was holding onto a pointer to data held by a shared dynamic library which was later unloaded as part of the shutdown process, but before the cache itself tried to do its own shutdown cleanup.
Comment 2 David Korth 2016-12-17 19:39:30 UTC
I'm using Qt 5.7.1. I don't remember if this problem happened with 5.7.0. (On Windows, I'm using Qt 5.5.1, and it doesn't crash when using native dialogs.)

I'll go through the 5.7.1 changelog again and see if there's anything relevant.
Comment 3 Nate Graham 2018-08-22 20:41:09 UTC
Works for me in KDE Frameworks 5.49 and Qt 5.9.5 or 5.11.1. Let's call this fixed, and re-open if it it's reproducible with newer versions. Thanks!