[frogr] Fix problem with ref counting for instances of FrogrPicture



commit 77709a158f34ec5a2044b7b46a0a600b645fd296
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Sat Dec 21 08:30:22 2013 +0000

    Fix problem with ref counting for instances of FrogrPicture
    
    The data type in the tree model was incorrectly declared as G_TYPE_POINTER,
    instead of G_TYPE_OBJECT, causing issues when adding/removing elements
    to the model (pictures not reffed/unreffed). Additionally, there were some
    missing and extra ref/unref calls that were easily causing unbalanced
    situations when doing simple things such as opening the detail dialog,
    adding to photosets or even visualizing the tooltips.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720156

 src/frogr-controller.c |    5 -----
 src/frogr-main-view.c  |   14 ++++++++++----
 2 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 27926a0..f976dd8 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -2765,7 +2765,6 @@ frogr_controller_show_details_dialog (FrogrController *self,
     }
 
   /* Show the dialog when possible */
-  g_slist_foreach (pictures, (GFunc) g_object_ref, NULL);
   priv->show_details_dialog_source_id =
     gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, DEFAULT_TIMEOUT,
                                   (GSourceFunc) _show_details_dialog_on_idle, pictures,
@@ -2794,7 +2793,6 @@ frogr_controller_show_add_tags_dialog (FrogrController *self,
     }
 
   /* Show the dialog when possible */
-  g_slist_foreach (pictures, (GFunc) g_object_ref, NULL);
   priv->show_add_tags_dialog_source_id =
     gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, DEFAULT_TIMEOUT,
                                   (GSourceFunc) _show_add_tags_dialog_on_idle, pictures,
@@ -2823,7 +2821,6 @@ frogr_controller_show_create_new_set_dialog (FrogrController *self,
     }
 
   /* Show the dialog when possible */
-  g_slist_foreach (pictures, (GFunc) g_object_ref, NULL);
   priv->show_create_new_set_dialog_source_id =
     gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, DEFAULT_TIMEOUT,
                                   (GSourceFunc) _show_create_new_set_dialog_on_idle, pictures,
@@ -2852,7 +2849,6 @@ frogr_controller_show_add_to_set_dialog (FrogrController *self,
     }
 
   /* Show the dialog when possible */
-  g_slist_foreach (pictures, (GFunc) g_object_ref, NULL);
   priv->show_add_to_set_dialog_source_id =
     gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, DEFAULT_TIMEOUT,
                                   (GSourceFunc) _show_add_to_set_dialog_on_idle, pictures,
@@ -2882,7 +2878,6 @@ frogr_controller_show_add_to_group_dialog (FrogrController *self,
     }
 
   /* Show the dialog when possible */
-  g_slist_foreach (pictures, (GFunc) g_object_ref, NULL);
   priv->show_add_to_group_dialog_source_id =
     gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, DEFAULT_TIMEOUT,
                                   (GSourceFunc) _show_add_to_group_dialog_on_idle, pictures,
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 91f6578..cbdc810 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -498,7 +498,7 @@ _initialize_ui (FrogrMainView *self)
   priv->tree_model = GTK_TREE_MODEL (gtk_list_store_new (3,
                                                          G_TYPE_STRING,
                                                          GDK_TYPE_PIXBUF,
-                                                         G_TYPE_POINTER));
+                                                         G_TYPE_OBJECT));
   gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), priv->tree_model);
   gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), PIXBUF_COL);
   gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
@@ -1251,6 +1251,7 @@ _on_icon_view_query_tooltip (GtkWidget *icon_view,
 
       /* Free memory */
       gtk_tree_path_free (path);
+      g_object_unref (picture);
       g_free (tooltip_str);
       g_free (filesize);
       g_free (filesize_str);
@@ -1321,7 +1322,7 @@ _get_selected_pictures (FrogrMainView *self)
                           -1);
 
       /* Add the picture to the list */
-      pictures = g_slist_prepend (pictures, g_object_ref (picture));
+      pictures = g_slist_prepend (pictures, picture);
       gtk_tree_path_free (path);
     }
 
@@ -1651,6 +1652,7 @@ _open_pictures_in_external_viewer (FrogrMainView *self)
 
   pictures = _get_selected_pictures (self);
   frogr_util_open_pictures_in_viewer (pictures);
+  g_slist_foreach (pictures, (GFunc)g_object_unref, NULL);
   g_slist_free (pictures);
 }
 
@@ -1676,6 +1678,7 @@ _remove_selected_pictures (FrogrMainView *self)
   _update_ui (self);
 
   /* Free */
+  g_slist_foreach (selected_pictures, (GFunc)g_object_unref, NULL);
   g_slist_free (selected_pictures);
 }
 
@@ -1953,6 +1956,7 @@ _model_picture_removed (FrogrController *controller,
   if (gtk_tree_model_get_iter_first (tree_model, &iter))
     {
       /* Look for the picture and remove it */
+      gboolean found = FALSE;
       do
         {
           FrogrPicture *picture_from_ui;
@@ -1972,10 +1976,11 @@ _model_picture_removed (FrogrController *controller,
               priv->sorted_pictures = g_slist_remove (priv->sorted_pictures, picture);
               g_object_unref (picture);
 
-              break;
+              found = TRUE;
             }
+          g_object_unref (picture_from_ui);
         }
-      while (gtk_tree_model_iter_next (tree_model, &iter));
+      while (!found && gtk_tree_model_iter_next (tree_model, &iter));
     }
 
   /* Update upload size in state description */
@@ -2239,6 +2244,7 @@ _frogr_main_view_dispose (GObject *object)
 
   if (priv->tree_model)
     {
+      gtk_list_store_clear (GTK_LIST_STORE (priv->tree_model));
       g_object_unref (priv->tree_model);
       priv->tree_model = NULL;
     }


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