Bug 408797 - kinit crashes when I close Dolphin while it shows the content of an audio CD
Summary: kinit crashes when I close Dolphin while it shows the content of an audio CD
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kinit
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.59.0
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
: 410119 411441 412103 412335 412337 413262 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-06-16 18:17 UTC by Patrick Silva
Modified: 2019-11-26 10:00 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Silva 2019-06-16 18:17:59 UTC
STEPS TO REPRODUCE
1. insert an audio cd
2. open dolhpin, click "Audio CD" entry in the places panel
3. wait for Dolphin to show the contents of the audio CD
4. close Dolphin

OBSERVED RESULT
plasma notifies about kdeinit5 crash

EXPECTED RESULT
no crash

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.16.0
KDE Frameworks Version: 5.59.0
Qt Version: 5.12.3

Thread 1 (Thread 0x7fe5432c8800 (LWP 18261)):
#0  0x00007fe546ab582f in raise () from /usr/lib/libc.so.6
#1  0x00007fe547945bef in KCrash::defaultCrashHandler(int) () from /usr/lib/libKF5Crash.so.5
#2  <signal handler called>
#3  0x00007fe546d03ab7 in std::__atomic_base<QMutexData*>::compare_exchange_strong (__m2=std::memory_order_acquire, __m1=std::memory_order_acquire, __p2=0x1, __p1=<synthetic pointer>: <optimized out>, this=0x0) at /usr/include/c++/8.3.0/bits/atomic_base.h:742
#4  std::atomic<QMutexData*>::compare_exchange_strong (__m2=std::memory_order_acquire, __m1=std::memory_order_acquire, __p2=0x1, __p1=<synthetic pointer>: <optimized out>, this=0x0) at /usr/include/c++/8.3.0/atomic:498
#5  QAtomicOps<QMutexData*>::testAndSetAcquire<QMutexData*> (currentValue=<synthetic pointer>, newValue=0x1, expectedValue=0x0, _q_value=...) at ../../include/QtCore/../../src/corelib/thread/qatomic_cxx11.h:290
#6  QBasicAtomicPointer<QMutexData>::testAndSetAcquire (currentValue=<synthetic pointer>: <optimized out>, newValue=0x1, expectedValue=0x0, this=0x0) at ../../include/QtCore/../../src/corelib/thread/qbasicatomic.h:263
#7  QBasicMutex::fastTryLock (current=<synthetic pointer>: <optimized out>, this=0x0) at thread/qmutex.h:107
#8  QMutex::lock (this=0x0) at thread/qmutex.cpp:222
#9  0x00007fe546f1b19b in QTextCodec::codecForLocale () at codecs/qtextcodec.cpp:103
#10 0x00007fe546d853fb in QString::fromLocal8Bit_helper (str=str@entry=0x5632196ffa08 "/run/user/1003", size=14) at tools/qstring.cpp:5569
#11 0x00007fe546e6af26 in QString::fromLocal8Bit (size=<optimized out>, str=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qstring.h:576
#12 QString::fromLocal8Bit (str=...) at ../../include/QtCore/../../src/corelib/tools/qstring.h:583
#13 QFile::decodeName (localFileName=...) at ../../include/QtCore/../../src/corelib/io/qfile.h:94
#14 QStandardPaths::writableLocation (type=<optimized out>) at io/qstandardpaths_unix.cpp:126
#15 0x00007fe5479449f0 in ?? () from /usr/lib/libKF5Crash.so.5
#16 0x00007fe54794550e in ?? () from /usr/lib/libKF5Crash.so.5
#17 0x00007fe547945a6d in KCrash::defaultCrashHandler(int) () from /usr/lib/libKF5Crash.so.5
#18 <signal handler called>
#19 0x00007fe546ab582f in raise () from /usr/lib/libc.so.6
#20 0x00007fe546aa0672 in abort () from /usr/lib/libc.so.6
#21 0x00007fe546af7e78 in __libc_message () from /usr/lib/libc.so.6
#22 0x00007fe546afe78a in malloc_printerr () from /usr/lib/libc.so.6
#23 0x00007fe546affeb4 in _int_free () from /usr/lib/libc.so.6
#24 0x00007fe546f09516 in QCoreGlobalData::~QCoreGlobalData (this=0x7fe547176640 <(anonymous namespace)::Q_QGS_globalInstance::innerFunction()::holder>, __in_chrg=<optimized out>) at ../../include/QtCore/../../src/corelib/tools/qlist.h:299
#25 0x00007fe546f0b399 in (anonymous namespace)::Q_QGS_globalInstance::Holder::~Holder (this=<optimized out>, __in_chrg=<optimized out>) at ker[m[mnel/qcoreglobaldata.cpp:47
#26 0x00007fe546ab7f2c in __run_exit_handlers () from /usr/lib/libc.so.6
#27 0x00007fe546ab805e in exit () from /usr/lib/libc.so.6
#28 0x00007fe54798f204 in ?? () from /usr/lib/qt/plugins/kf5/kio/file.so
#29 0x00007fe542ec8bdf in KIO::SlaveBase::dispatch(int, QByteArray const&) () from /usr/lib/libKF5KIOCore.so.5
#30 0x00007fe542ec9326 in KIO::SlaveBase::dispatchLoop() () from /usr/lib/libKF5KIOCore.so.5
#31 0x00007fe54798c98a in kdemain () from /usr/lib/qt/plugins/kf5/kio/file.so
#32 0x0000563218c263f9 in launch (argc=4, _name=0x5632196eed68 "/usr/lib/qt/plugins/kf5/kio/file.so", args=<optimized out>, cwd=<optimized out>, envc=0, envs=<optimized out>, reset_env=false, tty=0x0, avoid_loops=false, startup_id_str=0x563218c2919e "0") at /usr/src/debug/kinit-5.59.0/src/kdeinit/kinit.cpp:706
#33 0x0000563218c27502 in handle_launcher_request (sock=8, who=<optimized out>) at /usr/src/debug/kinit-5.59.0/src/kdeinit/kinit.cpp:1146
#34 0x0000563218c27ead in handle_requests (waitForPid=0) at /usr/src/debug/kinit-5.59.0/src/kdeinit/kinit.cpp:1339
#35 0x0000563218c22b7a in main (argc=5, argv=<optimized out>) at /usr/src/debug/kinit-5.59.0/src/kdeinit/kinit.cpp:1785
Comment 1 Christoph Feck 2019-07-03 10:21:11 UTC
https://cgit.kde.org/kio.git/tree/src/ioslaves/file/file.cpp#n719

I wonder if ::exit() is really the only way to "deal" with errors. Someone familiar with KIO error handling would need to investigate how to do it properly.
Comment 2 Christoph Feck 2019-08-14 02:50:40 UTC
*** Bug 410119 has been marked as a duplicate of this bug. ***
Comment 3 Patrick Silva 2019-09-15 13:05:20 UTC
I can't reproduce this crash after upgrade to frameworks 5.62 on Arch Linux.
Comment 4 Loïc Yhuel 2019-09-20 01:39:00 UTC
(In reply to Christoph Feck from comment #1)
> https://cgit.kde.org/kio.git/tree/src/ioslaves/file/file.cpp#n719
> 
> I wonder if ::exit() is really the only way to "deal" with errors. Someone
> familiar with KIO error handling would need to investigate how to do it
> properly.

It has now been removed : https://cgit.kde.org/kio.git/commit/?id=512967f6f4e887d4a5a0a7da5893055e1c840ce5.

But there is an exit() later in kinit, leading to a crash in QCoreGlobalData::~QCoreGlobalData, see the backtrace which was attached to https://bugs.kde.org/show_bug.cgi?id=411441.

The root cause is https://cgit.kde.org/kio.git/commit/src/ioslaves/file/file.cpp?id=6738a8b2f71c527f30a624b0b560f79d992715d3.
Until Qt 5.12 (https://codereview.qt-project.org/c/qt/qtbase/+/230316), you are not allowed to delete a QTextCodec.

Since kdeinit does not call QLibrary::unload, the file.so plugin stays in memory, so you can just do "(void)new LegacyCodec;", QCoreGlobalData::~QCoreGlobalData will delete it on exit.
Comment 5 Loïc Yhuel 2019-09-20 01:54:18 UTC
*** Bug 411441 has been marked as a duplicate of this bug. ***
Comment 6 Patrick Silva 2019-09-20 02:20:18 UTC
Is bug 412103 a duplicate?
Comment 7 Loïc Yhuel 2019-09-20 02:52:40 UTC
*** Bug 412103 has been marked as a duplicate of this bug. ***
Comment 8 Loïc Yhuel 2019-09-20 02:59:07 UTC
(In reply to Loïc Yhuel from comment #4)
> Until Qt 5.12 (https://codereview.qt-project.org/c/qt/qtbase/+/230316), you
> are not allowed to delete a QTextCodec.
> 
https://bugs.kde.org/show_bug.cgi?id=412103 made me realize that even with Qt 5.12, allocating a QTextCodec on the stack is not valid, unless there is no exit() anywhere below, since if it isn't destroyed before QCoreGlobalData, the delete operator will be called, which will call free on a stack address.

So, even with Qt 5.12, the proper solution is to allocate it on the heap : "(void)new LegacyCodec;".
Comment 9 Christoph Feck 2019-09-21 13:16:58 UTC
Thanks for the investigation, Loïc! Do you want to submit a patch to phabricator?
Comment 10 Cherkah 2019-09-22 09:42:42 UTC
same kdeinit5 crash when closing dolphin or kate.

debian/kde sid
Comment 11 Loïc Yhuel 2019-09-22 19:35:37 UTC
(In reply to Christoph Feck from comment #9)
> Thanks for the investigation, Loïc! Do you want to submit a patch to
> phabricator?
Done, https://phabricator.kde.org/D24150
Comment 12 Christoph Feck 2019-09-25 20:28:22 UTC
*** Bug 412337 has been marked as a duplicate of this bug. ***
Comment 13 Christoph Feck 2019-09-25 20:28:40 UTC
*** Bug 412335 has been marked as a duplicate of this bug. ***
Comment 14 David Faure 2019-09-27 00:56:21 UTC
Git commit 2c379fecccbf5e2c0b20a93c843c009f2f597318 by David Faure.
Committed on 27/09/2019 at 00:56.
Pushed by dfaure into branch 'master'.

Fix crash on exit in kio_file

Summary:
All QTextCodec are deleted by QCoreGlobalData on exit, so they must be allocated on the heap.
Before Qt 5.12, it is even not allowed to delete them.

Reviewers: cfeck, dfaure, broulik

Reviewed By: dfaure

Subscribers: aacid, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D24150

M  +2    -1    src/ioslaves/file/file.cpp

https://commits.kde.org/kio/2c379fecccbf5e2c0b20a93c843c009f2f597318
Comment 15 Christoph Feck 2019-11-26 10:00:35 UTC
*** Bug 413262 has been marked as a duplicate of this bug. ***