[vte] widget: Avoid invalidation from unrealize



commit 57c3a07947f301d0363e9449b089da800a7e08d7
Author: Christian Persch <chpe src gnome org>
Date:   Sat Sep 1 19:28:40 2018 +0200

    widget: Avoid invalidation from unrealize
    
    On unrealize, reset the IM preedit data without causing
    an invalidation, which would access data already destroyed.
    
    https://gitlab.gnome.org/GNOME/vte/issues/29

 src/vte.cc         | 28 +++++++++++++++-------------
 src/vteinternal.hh |  1 +
 src/widget.cc      |  2 +-
 3 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 32323f46..7f8e79dd 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4356,6 +4356,18 @@ Terminal::im_preedit_set_active(bool active) noexcept
        m_im_preedit_active = active;
 }
 
+void
+Terminal::im_preedit_reset() noexcept
+{
+        m_im_preedit.clear();
+        m_im_preedit.shrink_to_fit();
+        m_im_preedit_cursor = 0;
+        if (m_im_preedit_attrs != nullptr) {
+                pango_attr_list_unref(m_im_preedit_attrs);
+                m_im_preedit_attrs = nullptr;
+        }
+}
+
 void
 Terminal::im_preedit_changed(char const* str,
                              int cursorpos,
@@ -4365,13 +4377,10 @@ Terminal::im_preedit_changed(char const* str,
         * for repainting. */
        invalidate_cursor_once();
 
+        im_preedit_reset();
        m_im_preedit = str;
-
-       if (m_im_preedit_attrs != nullptr) {
-               pango_attr_list_unref(m_im_preedit_attrs);
-       }
-       m_im_preedit_attrs = attrs;
-       m_im_preedit_cursor = cursorpos;
+        m_im_preedit_attrs = attrs;
+        m_im_preedit_cursor = cursorpos;
 
         /* Invalidate again with the new cursor position */
        invalidate_cursor_once();
@@ -8240,13 +8249,6 @@ Terminal::widget_unrealize()
        match_hilite_clear();
 
        m_im_preedit_active = FALSE;
-        m_im_preedit.clear();
-        m_im_preedit.shrink_to_fit();
-       if (m_im_preedit_attrs != NULL) {
-               pango_attr_list_unref(m_im_preedit_attrs);
-               m_im_preedit_attrs = NULL;
-       }
-       m_im_preedit_cursor = 0;
 
        /* Clean up our draw structure. */
        if (m_draw != NULL) {
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 785901b8..1652ca5f 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -855,6 +855,7 @@ public:
 
         void im_commit(char const* text);
         void im_preedit_set_active(bool active) noexcept;
+        void im_preedit_reset() noexcept;
         void im_preedit_changed(char const* str,
                                 int cursorpos,
                                 PangoAttrList* attrs) noexcept;
diff --git a/src/widget.cc b/src/widget.cc
index 4baf42db..0f2e509e 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -349,7 +349,7 @@ Widget::unrealize() noexcept
                                              G_SIGNAL_MATCH_DATA,
                                              0, 0, NULL, NULL,
                                              this);
-        m_terminal->im_preedit_changed("", 0, nullptr);
+        m_terminal->im_preedit_reset();
         gtk_im_context_set_client_window(m_im_context.get(), nullptr);
         m_im_context.reset();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]