Changeset 2944

Show
Ignore:
Timestamp:
11/13/07 23:45:39
Author:
pvanhoof
Message:

Leak when using tny_list_copy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymailui-gtk/tny-gtk-account-list-model.c

    r2943 r2944  
    4646 * tny_gtk_account_list_model_new: 
    4747 * 
    48  * Create a new #GtkTreeModel instance suitable for showing a #TnyMimePart. 
    49  * 
    50  * Return value: a new #GtkTreeModel instance suitable for showing a #TnyMimePart 
     48 * Create a new #GtkTreeModel instance suitable for showing a list of accounts. 
     49 * Note that when using gtk_combo_box_set_model or gtk_tree_view_set_model, the  
     50 * view will add its reference to your model instance. If you want the view to 
     51 * become the owner, you must get rid of your initial reference. 
     52 * 
     53 * <informalexample><programlisting> 
     54 * GtkTreeModel *model = tny_gtk_account_list_model_new (); 
     55 * GtkTreeView *view = ...; 
     56 * gtk_tree_view_set_model (view, model); 
     57 * g_object_unref (model); // this is probably what you want to do 
     58 * </programlisting></informalexample> 
     59 * 
     60 * Return value: a new #GtkTreeModel instance suitable for showing accounts 
    5161 **/ 
    5262GtkTreeModel* 
     
    6575 
    6676        g_mutex_lock (me->iterator_lock); 
    67         if (me->first) 
     77        if (me->first) { 
     78                if (me->first_needs_unref) 
     79                        g_list_foreach (me->first, (GFunc)g_object_unref, NULL); 
     80                me->first_needs_unref = FALSE; 
    6881                g_list_free (me->first); 
     82        } 
    6983        me->first = NULL; 
    7084        g_mutex_unlock (me->iterator_lock); 
     
    97111        me->iterator_lock = g_mutex_new (); 
    98112        me->first = NULL; 
     113        me->first_needs_unref = FALSE; 
    99114 
    100115        gtk_list_store_set_column_types (store,  
     
    225240        list_copy = g_list_copy (me->first); 
    226241        g_list_foreach (list_copy, (GFunc)g_object_ref, NULL); 
     242        copy->first_needs_unref = TRUE; 
    227243        copy->first = list_copy; 
    228244        g_mutex_unlock (me->iterator_lock);     
  • trunk/libtinymailui-gtk/tny-gtk-account-list-model.h

    r2825 r2944  
    5353        GMutex *iterator_lock; 
    5454        GList *first; 
     55        gboolean first_needs_unref; 
    5556}; 
    5657 
  • trunk/libtinymailui-gtk/tny-gtk-attach-list-model.c

    r2825 r2944  
    123123} 
    124124 
    125 static void  
    126 destroy_parts (gpointer item, gpointer user_data) 
    127 { 
    128         if (item && G_IS_OBJECT (item)) 
    129                 g_object_unref (G_OBJECT (item)); 
    130         return; 
    131 } 
    132  
    133125static void 
    134126tny_gtk_attach_list_model_finalize (GObject *object) 
     
    138130 
    139131        g_mutex_lock (me->iterator_lock); 
    140         if (me->first) 
    141         { 
    142                 g_list_foreach (me->first, destroy_parts, NULL); 
    143                 g_list_free (me->first); me->first = NULL; 
     132        if (me->first) { 
     133                if (me->first_needs_unref) 
     134                        g_list_foreach (me->first, (GFunc)g_object_unref, NULL); 
     135                me->first_needs_unref = FALSE; 
     136                g_list_free (me->first); 
    144137        } 
     138        me->first = NULL; 
    145139        g_mutex_unlock (me->iterator_lock); 
    146140 
     
    177171        static GType types[] = { G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_OBJECT }; 
    178172 
     173 
    179174        priv->theme = NULL; 
    180175        types[0] = GDK_TYPE_PIXBUF; 
    181176        me->iterator_lock = g_mutex_new (); 
    182177        me->first = NULL; 
    183      
     178        me->first_needs_unref = FALSE; 
     179 
    184180        gtk_list_store_set_column_types (store,  
    185181                TNY_GTK_ATTACH_LIST_MODEL_N_COLUMNS, types); 
     
    208204 
    209205        /* Prepend something to the list */ 
    210         g_object_ref (G_OBJECT (item)); 
    211  
    212         me->first = g_list_prepend (me->first, item); 
    213206 
    214207        tny_gtk_attach_list_model_add (me, TNY_MIME_PART (item),  
    215208                gtk_list_store_prepend); 
    216209 
     210        me->first = g_list_prepend (me->first, item); 
     211 
    217212        g_mutex_unlock (me->iterator_lock); 
    218213} 
     
    226221 
    227222        /* Append something to the list */ 
    228         g_object_ref (G_OBJECT (item)); 
    229      
    230         me->first = g_list_append (me->first, item); 
     223 
    231224        tny_gtk_attach_list_model_add (me, TNY_MIME_PART (item),  
    232225                gtk_list_store_append); 
     226        me->first = g_list_append (me->first, item); 
    233227 
    234228        g_mutex_unlock (me->iterator_lock); 
     
    278272                { 
    279273                        gtk_list_store_remove (GTK_LIST_STORE (me), &iter); 
    280                        g_object_unref (G_OBJECT (item)); 
     274                       g_object_unref (item); 
    281275                        break; 
    282276                } 
    283                 g_object_unref (G_OBJECT (citem)); 
     277                g_object_unref (citem); 
    284278          } 
    285279     
     
    306300        list_copy = g_list_copy (me->first); 
    307301        g_list_foreach (list_copy, (GFunc)g_object_ref, NULL); 
     302        copy->first_needs_unref = TRUE; 
    308303        copy->first = list_copy; 
    309304        g_mutex_unlock (me->iterator_lock); 
  • trunk/libtinymailui-gtk/tny-gtk-attach-list-model.h

    r2825 r2944  
    5656        GList *first; 
    5757        GMutex *iterator_lock; 
     58        gboolean first_needs_unref; 
    5859}; 
    5960 
  • trunk/libtinymailui-gtk/tny-gtk-folder-store-tree-model.c

    r2943 r2944  
    520520 
    521521        g_mutex_lock (me->iterator_lock); 
    522         if (me->first) 
     522        if (me->first) { 
     523                if (me->first_needs_unref) 
     524                        g_list_foreach (me->first, (GFunc)g_object_unref, NULL); 
     525                me->first_needs_unref = FALSE; 
    523526                g_list_free (me->first);  
     527        } 
    524528        me->first = NULL; 
    525529        g_mutex_unlock (me->iterator_lock); 
     
    558562        me->store_obs = NULL; 
    559563        me->iterator_lock = g_mutex_new (); 
     564        me->first_needs_unref = FALSE; 
    560565 
    561566        gtk_tree_store_set_column_types (store,  
     
    734739        list_copy = g_list_copy (me->first); 
    735740        g_list_foreach (list_copy, (GFunc)g_object_ref, NULL); 
     741        copy->first_needs_unref = TRUE; 
    736742        copy->first = list_copy; 
    737743        g_mutex_unlock (me->iterator_lock); 
  • trunk/libtinymailui-gtk/tny-gtk-folder-store-tree-model.h

    r2926 r2944  
    6161        GMutex *iterator_lock; 
    6262        TnyFolderStoreQuery *query; 
     63        gboolean first_needs_unref; 
    6364}; 
    6465