https://bugs.kde.org/show_bug.cgi?id=424882

Igor Kushnir <igor...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Latest Commit|                            |https://invent.kde.org/kdev
                   |                            |elop/kdevelop/-/commit/42a5
                   |                            |80e2fdd2187ca155d89b480862c
                   |                            |9775b6728
         Resolution|---                         |FIXED
   Version Fixed In|                            |5.13.231200

--- Comment #8 from Igor Kushnir <igor...@gmail.com> ---
Git commit 42a580e2fdd2187ca155d89b480862c9775b6728 by Igor Kushnir.
Committed on 15/09/2023 at 14:14.
Pushed by igorkushnir into branch 'master'.

Don't emit documentUrlChanged twice while saving a text document

When KTextEditor::Document is renamed during saving, it emits a
KTextEditor::Document::documentUrlChanged signal. The slot
TextDocument::documentUrlChanged() is connected to this signal and calls
PartDocument::setUrl(), which in turn calls notifyUrlChanged(), from
which the IDocumentController::documentUrlChanged signal is emitted.
TextDocument::save() saves its KTextEditor::Document and also calls
notifyUrlChanged() if the KTextEditor::Document's URL changes in the
process. Thus the IDocumentController::documentUrlChanged signal is
emitted twice for a single URL change.

DocumentControllerPrivate::changeDocumentUrl() is connected to the
IDocumentController::documentUrlChanged signal. During the duplicate
second signal emission and invocation of this function, the renamed
document is already stored under the correct URL in
DocumentControllerPrivate::documents. changeDocumentUrl() then wrongly
assumes that the renamed document is saved under the name of another
open document and closes it. As the renamed document is not modified,
changeDocumentUrl() then proceeds to insert it into
DocumentControllerPrivate::documents, even though the document is
already closed and is about to be destroyed. The next time
DocumentController::openDocuments() is called, it attempts to
dynamic_cast to Sublime::Document* each element of
DocumentControllerPrivate::documents, including the now-dangling pointer
to the renamed document, which results in a segmentation fault.

The fix is to remove the explicit notifyUrlChanged() call from
TextDocument::save() and rely on KTextEditor::Document's URL change
notifications.

Add an assertion that catches the wrong assumption in
changeDocumentUrl().

Tarcisio Fischer tracked the bug to changeDocumentUrl() (thanks!) and
proposed an alternative fix within this function: prevent the wrong
assumption by checking the condition asserted in this commit. The
alternative fix is less efficient, because it keeps the duplicate signal
emission.
Related: bug 456338
FIXED-IN: 5.13.231200

M  +1    -0    kdevplatform/shell/documentcontroller.cpp
M  +1    -8    kdevplatform/shell/textdocument.cpp

https://invent.kde.org/kdevelop/kdevelop/-/commit/42a580e2fdd2187ca155d89b480862c9775b6728

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to