Bug 461558

Summary: Kate crashes when closing after saving a new file overwriting a file in another kate tab.
Product: [Applications] kate Reporter: Oded Arbel <oded>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: christoph
Priority: NOR Keywords: drkonqi
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: New crash information added by DrKonqi

Description Oded Arbel 2022-11-07 18:22:27 UTC
Application: kate (22.11.70)

Qt Version: 5.15.7
Frameworks Version: 5.100.0
Operating System: Linux 5.19.0-23-generic x86_64
Windowing System: Wayland
Distribution: KDE neon Unstable Edition
DrKonqi: 5.26.80 [CoredumpBackend]

-- Information about the crash:
This seems very reproducable:

1. Open a file in Kate.
2. In the same window, open a new empty tab and type something.
3. Save the new file to the same file that was opened in step 1.
4. Close the first file by middle-clicking its tab.
5. Close the second file - for example, by exiting Kate.

I think it has something to do with the temporary files, because I see this in the terminal right before the crash:

---8<---
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: old: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp") new: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp")
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: old: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp") new: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp")
kf.texteditor: 
kf.texteditor: new range:  [ (0, 0)  ->  (8, 0) ]
kf.texteditor: old range:  [ (0, 0)  ->  (9, 0) ]
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: "/home/odeda/.test.txt.kate-swp"
kf.kio.core.dirlister: old: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp") new: ".test.txt.kate-swp" QUrl("file:///home/odeda/.test.txt.kate-swp")

---8<---

The reporter is unsure if this crash is reproducible.

-- Backtrace (Reduced):
#6  0x00007f9c911dba0e in KateMwModOnHdDialog::slotSelectionChanged(QTreeWidgetItem*, QTreeWidgetItem*) (this=<optimized out>, current=0x563178f4c620) at ./apps/lib/katemwmodonhddialog.cpp:240
#7  0x00007f9c8fdb10f4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffdb5a14a30, r=0x563176b06670, this=0x563178f02e40) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#8  doActivate<false>(QObject*, int, void**) (sender=0x563176b08670, signal_index=24, argv=0x7ffdb5a14a30) at kernel/qobject.cpp:3919
#9  0x00007f9c90d1d972 in QTreeWidget::currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*) () at /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#10 0x00007f9c8fdb1128 in doActivate<false>(QObject*, int, void**) (sender=0x5631789dcca0, signal_index=4, argv=0x7ffdb5a14b30) at kernel/qobject.cpp:3931


Reported using DrKonqi
Comment 1 Oded Arbel 2022-11-07 18:22:29 UTC
Created attachment 153562 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.
Comment 2 Oded Arbel 2022-11-07 18:29:07 UTC
It may be a requirement for the documents side bar to be open, not sure.
Comment 3 Bug Janitor Service 2022-11-12 17:29:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1007
Comment 4 Christoph Cullmann 2022-11-12 17:39:03 UTC
If you have time, you could try out my patch, if feasible.
Comment 5 Christoph Cullmann 2022-11-13 21:59:30 UTC
Git commit a988fb0d4ccdd714f9998789ad09a7cb301da8a6 by Christoph Cullmann.
Committed on 13/11/2022 at 21:23.
Pushed by cullmann into branch 'master'.

avoid dangling document pointers

M  +20   -7    apps/lib/katemwmodonhddialog.cpp
M  +1    -0    apps/lib/katemwmodonhddialog.h

https://invent.kde.org/utilities/kate/commit/a988fb0d4ccdd714f9998789ad09a7cb301da8a6
Comment 6 Oded Arbel 2022-11-14 19:54:46 UTC
with current master, I can't reproduce the crash anymore, but I did observe a new weird behavior that may be related to the change:

When I press CTRL+S on a new document (it doesn't matter if its the first document or another) or CTRL+SHIFT+S on an existing document, I get two file save dialog - one on top of the other. If I dismiss one of them and save with the other, the file is saved - doesn't matter which one I dismiss.