From 89d41f2629b9d98069fa7c1db70821a14da57523 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 9 Aug 2018 00:37:28 +0200
Subject: Fixed reference counting when switching panels.

---
 src/gtkext/gtkbufferdisplay.c |  2 +-
 src/gtkext/gtkdisplaypanel.c  |  3 +--
 src/gui/menus/view.c          | 14 ++++++++------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/gtkext/gtkbufferdisplay.c b/src/gtkext/gtkbufferdisplay.c
index fccea38..f41c4e3 100644
--- a/src/gtkext/gtkbufferdisplay.c
+++ b/src/gtkext/gtkbufferdisplay.c
@@ -205,7 +205,7 @@ static void gtk_buffer_display_init(GtkBufferDisplay *display)
 
 static void gtk_buffer_display_dispose(GtkBufferDisplay *display)
 {
-    g_object_unref(G_OBJECT(display->view));
+    g_clear_object(&display->view);
 
     G_OBJECT_CLASS(gtk_buffer_display_parent_class)->dispose(G_OBJECT(display));
 
diff --git a/src/gtkext/gtkdisplaypanel.c b/src/gtkext/gtkdisplaypanel.c
index 0c3a6b9..4b21d8c 100644
--- a/src/gtkext/gtkdisplaypanel.c
+++ b/src/gtkext/gtkdisplaypanel.c
@@ -231,8 +231,7 @@ static void gtk_display_panel_loaded_interface_init(GLoadedPanelInterface *iface
 
 static void gtk_display_panel_dispose(GtkDisplayPanel *panel)
 {
-    if (panel->options != NULL)
-        g_object_unref(G_OBJECT(panel->options));
+    g_clear_object(&panel->options);
 
     G_OBJECT_CLASS(gtk_display_panel_parent_class)->dispose(G_OBJECT(panel));
 
diff --git a/src/gui/menus/view.c b/src/gui/menus/view.c
index 6f113e2..4dca039 100644
--- a/src/gui/menus/view.c
+++ b/src/gui/menus/view.c
@@ -751,8 +751,8 @@ static void change_current_view_support(unsigned int wanted)
     GtkDockStation *station;                /* Base du remplacement        */
     GLoadedContent *content;                /* Contenu représenté          */
     GtkWidget *support;                     /* Nouvel afficheur généraliste*/
-    GLineCursor *cursor;                    /* Position à transmettre      */
     GLoadedPanel *new;                      /* Panneau encapsulé           */
+    GLineCursor *cursor;                    /* Position à transmettre      */
 
     panel = get_current_view();
 
@@ -764,20 +764,22 @@ static void change_current_view_support(unsigned int wanted)
 
     g_object_unref(G_OBJECT(content));
 
-    cursor = g_loaded_panel_get_cursor(panel);
-
     gtk_dock_panel_change_active_widget(station, support);
 
     new = G_LOADED_PANEL(get_loaded_panel_from_built_view(support));
 
-    g_loaded_panel_set_cursor(new, cursor);
+    cursor = g_loaded_panel_get_cursor(panel);
+
+    if (cursor != NULL)
+    {
+        g_loaded_panel_set_cursor(new, cursor);
+        g_object_unref(G_OBJECT(cursor));
+    }
 
     change_editor_items_current_view(new);
 
     g_object_unref(G_OBJECT(new));
 
-    g_object_unref(G_OBJECT(cursor));
-
     g_object_unref(G_OBJECT(panel));
 
 }
-- 
cgit v0.11.2-87-g4458