[evolution/gnome-40] Use GWeakRef in html_editor_actions_notify_html_mode_cb()



commit 86196991bf2108e7f17ae6db6e52cb22f1801422
Author: Milan Crha <mcrha redhat com>
Date:   Fri Apr 16 12:46:06 2021 +0200

    Use GWeakRef in html_editor_actions_notify_html_mode_cb()
    
    The function issues an on-idle callback using the editor, which can
    be freed before the idle callback is called. Use GWeakRef to know
    whether the editor was freed meanwhile or not.

 src/e-util/e-html-editor-actions.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/e-util/e-html-editor-actions.c b/src/e-util/e-html-editor-actions.c
index ab295f02da..17869ff4f2 100644
--- a/src/e-util/e-html-editor-actions.c
+++ b/src/e-util/e-html-editor-actions.c
@@ -585,12 +585,14 @@ action_language_cb (GtkToggleAction *toggle_action,
 static gboolean
 update_mode_combobox (gpointer data)
 {
-       EHTMLEditor *editor = data;
+       GWeakRef *weak_ref = data;
+       EHTMLEditor *editor;
        EContentEditor *cnt_editor;
        GtkAction *action;
        gboolean is_html;
 
-       if (!E_IS_HTML_EDITOR (editor))
+       editor = g_weak_ref_get (weak_ref);
+       if (!editor)
                return FALSE;
 
        cnt_editor = e_html_editor_get_content_editor (editor);
@@ -601,6 +603,8 @@ update_mode_combobox (gpointer data)
        gtk_radio_action_set_current_value (
                GTK_RADIO_ACTION (action), (is_html ? 1 : 0));
 
+       g_object_unref (editor);
+
        return FALSE;
 }
 
@@ -622,7 +626,7 @@ html_editor_actions_notify_html_mode_cb (EContentEditor *cnt_editor,
 
        /* This must be done from idle callback, because apparently we can change
         * current value in callback of current value change */
-       g_idle_add (update_mode_combobox, editor);
+       g_idle_add_full (G_PRIORITY_HIGH_IDLE, update_mode_combobox, e_weak_ref_new (editor), 
(GDestroyNotify) e_weak_ref_free);
 
        action_group = editor->priv->html_actions;
        gtk_action_group_set_visible (action_group, is_html);


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