Fix crash on exit in kio_file
ClosedPublic

Authored by hwti on Sep 22 2019, 7:28 PM.

Details

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.

BUG: 408797

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
hwti created this revision.Sep 22 2019, 7:28 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 22 2019, 7:28 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
hwti requested review of this revision.Sep 22 2019, 7:28 PM
aacid added a subscriber: aacid.Sep 22 2019, 8:09 PM

why the void? do you get a warning otherwise?

Also a comment in that line quoting the Qt docs "Note that you should not delete codecs yourself: once created they become Qt's responsibility." makes sense IMHO otherwise someone will move it back to the old code to not have a leak

hwti added a comment.Sep 22 2019, 9:00 PM

why the void? do you get a warning otherwise?

No, but it is used in several places in the repository (and in Qt), so I suppose it might generate one depending on the compiler.

Also a comment in that line quoting the Qt docs "Note that you should not delete codecs yourself: once created they become Qt's responsibility." makes sense IMHO otherwise someone will move it back to the old code to not have a leak

OK, done (but the void should already show that not storing it in a variable, so not deleting it, is deliberate).

hwti updated this revision to Diff 66633.Sep 22 2019, 9:01 PM

I (thought I) fixed this crash already in commit 512967f6f4e887d4a5a0 by removing the ::exit() call (which appears in the backtrace of that bug report).

This being said, I'm not objecting to this patch, but I am wondering if you can still experience this crash with a kio that includes my commit above (from Sep 6).

hwti added a comment.Sep 23 2019, 3:42 AM

I (thought I) fixed this crash already in commit 512967f6f4e887d4a5a0 by removing the ::exit() call (which appears in the backtrace of that bug report).

This being said, I'm not objecting to this patch, but I am wondering if you can still experience this crash with a kio that includes my commit above (from Sep 6).

QCoreGlobalData destructor is called on any exit, even when returning from main (but there is an exit call in kdeinit5 anyway).
If there is no other possible exit() call before the kdemain function in file.cpp returns, then you avoided the issue for Qt >= 5.12 : destroying the QTextCodec unregisters it, so it isn't in the list any more when QCoreGlobalData destructor is called.
But older Qt versions do not have this logic, so QCoreGlobalData destructor often crashes when trying to call the LegacyTextCodec destructor, since the object has already been destroyed and is above the stack pointer. Even if it doesn't crash, free() would then be called on a stack address.

dfaure accepted this revision.Sep 27 2019, 12:54 AM

Ah, I see, OK.

This revision is now accepted and ready to land.Sep 27 2019, 12:54 AM
dfaure closed this revision.Sep 27 2019, 12:56 AM