Index: gtktreemodelfilter.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelfilter.c,v
retrieving revision 1.33
diff -u -p -r1.33 gtktreemodelfilter.c
--- gtktreemodelfilter.c	1 Sep 2005 05:11:43 -0000	1.33
+++ gtktreemodelfilter.c	13 Sep 2005 19:43:06 -0000
@@ -537,6 +537,16 @@ gtk_tree_model_filter_build_level (GtkTr
 
           if (!new_level->parent_level)
             filter->priv->root_level_visible++;
+          else
+            {
+              GtkTreeIter f_iter;
+
+              f_iter.stamp = filter->priv->stamp;
+              f_iter.user_data = new_level;
+              f_iter.user_data2 = &(g_array_index (new_level->array, FilterElt, new_level->array->len - 1));
+
+              gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &f_iter);
+            }
         }
       i++;
     }
@@ -576,6 +586,17 @@ gtk_tree_model_filter_free_level (GtkTre
       if (g_array_index (filter_level->array, FilterElt, i).children)
         gtk_tree_model_filter_free_level (filter,
                                           FILTER_LEVEL (g_array_index (filter_level->array, FilterElt, i).children));
+
+      if (filter_level->parent_level)
+        {
+          GtkTreeIter f_iter;
+
+          f_iter.stamp = filter->priv->stamp;
+          f_iter.user_data = filter_level;
+          f_iter.user_data2 = &(g_array_index (filter_level->array, FilterElt, i));
+
+          gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), &f_iter);
+        }
     }
 
   if (!filter_level->parent_level)
@@ -1093,6 +1114,8 @@ gtk_tree_model_filter_row_changed (GtkTr
 
       if (!level->parent_level)
         filter->priv->root_level_visible--;
+      else
+        gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), &iter);
 
       gtk_tree_model_filter_remove_node (filter, &iter, TRUE);
 
@@ -1159,6 +1182,8 @@ gtk_tree_model_filter_row_changed (GtkTr
 
   if (!level->parent_level)
     filter->priv->root_level_visible++;
+  else
+    gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &iter);
 
   /* update stamp */
   gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
@@ -1338,6 +1363,16 @@ gtk_tree_model_filter_row_inserted (GtkT
 
       if (!level->parent_level)
         filter->priv->root_level_visible++;
+      else
+        {
+          GtkTreeIter f_iter;
+
+          f_iter.stamp = filter->priv->stamp;
+          f_iter.user_data = level;
+          f_iter.user_data2 = &g_array_index (level->array, FilterElt, index);
+
+          gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &f_iter);
+        }
     }
 
   /* another iteration to update the references of children to parents. */
@@ -1576,7 +1611,10 @@ gtk_tree_model_filter_row_deleted (GtkTr
       gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
       iter.stamp = filter->priv->stamp;
 
-      while (elt->ref_count > 0)
+      /* the filter model's reference on the child node is released
+       * below.
+       */
+      while (elt->ref_count > 1)
         gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
                                                FALSE);
     }
@@ -1589,6 +1627,9 @@ gtk_tree_model_filter_row_deleted (GtkTr
   else
     {
       FilterElt *tmp;
+
+      if (level->parent_level)
+        gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), &iter);
 
       /* remove the row */
       tmp = bsearch_elt_with_offset (level->array, elt->offset, &i);
