Bug report - GtkTreeStore and GtkTreeIter error after using "gtk_tree_store_clear ()"
Steps to reproduce
- Have a GtkTreeStore allocated and filled with some data
- Clear that GtkTreeStore using "gtk_tree_store_clear ()"
- Re-fill the cleared GtkTreeStore with some new data
- Try to access the data using "gtk_tree_model_get_iter_first ()" and "gtk_tree_model_iter_next ()"
void accessing_the_data (GtkTreeStore * model)
{
GtkTreeModel * tree_model = GTK_TREE_MODEL(model);
GtkTreeIter iter;
gboolean dothis;
gchar * str;
if (gtk_tree_model_get_iter_first (tree_model, & iter))
{
dothis = TRUE;
while (dothis)
{
gtk_tree_model_get (tree_model, & iter, 0, & str, -1);
// this will eventually continues after the end of the actual content
// of the tree_model and somehow reach the old structure.
// If I print "str" I got the old data coming up
// In my opinion "gtk_tree_store_clear" should have cleared the last pointer.
dothis = gtk_tree_model_iter_next (tree_model, & iter);
}
}
void fill_this_tree_store (GtkTreeStore * model)
{
GtkTreeIter iter;
gtk_tree_store_append (model, & iter, NULL);
gtk_tree_store_set (model, & iter, 0, "Hello", -1);
}
void clear_this_tree (GtkTreeStore * model)
{
gtk_tree_store_clear (model);
fill_this_tree_store (model);
accessing_the_data (model);
}
Current behavior
What should be the last GtkTreeIter of the new GtkTreeStore actually points towards the first GtkTreeIter of the old GtkTreeStore, therefore the "gtk_tree_model_iter_next ()" does not stop where it should, as I was using the data retrieved at each step this behavior had the consequence to break down my application. I needed to use Valgrind to find out where the error was coming from.
Expected outcome
The "pointer to next" of the last GtkTreeIter of the new GtkTreeStore should be voided.
Version information
- GTK 3.24 (rpm package: gtk3-3.24.11-1.fc30.x86_64)
- Fedora Linux 30
- Gnome 3.32.2
Edited by Sébastien Le Roux