possible memory leak help.



Hi,
I have a memory leak problem which I can't seem to understand.

I have a GtkTreeview/ GtkTreeModelFilter/ GtkTreeStore setup.
I have traced it to a case where memory leaks when I call "gtk_tree_store_set" multiple times.

Here is a snipnet of my code demonstrating the problem. Am I suppose to free something but I didn't?

... I have selection change call back function setup...

g_signal_connect (G_OBJECT (select), "changed",
                     G_CALLBACK (FilterviewSelectionChanged_cb), NULL);

void FilterviewSelectionChanged_cb(GtkTreeSelection *sel, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  gboolean col0;
  gchar *col1;
  GString *key_col1;
  GTree *list;

  if (gtk_tree_selection_get_selected (sel,&model,&iter))
  {
     gtk_tree_model_get (model,&iter,0,&col0, -1);
     gtk_tree_model_get (model,&iter,1,&col1, -1);
     g_print ("filterview row selected, col0: %d, col1: %s\n", col0,col1);

     key_col1 = g_string_new (col1);
     list = g_tree_lookup (filterlists, key_col1);
     if (list) //found
{ //Not calling GameviewDispalyGTree(list) doesn't seem to show much //memory leak... Lets follow it and see what GameviewDisplayGTree is doing...
        GameviewDisplayGTree(list);
     }
g_free (col1);
     g_string_free (key_col1, TRUE);
  }
}

void GameviewDisplayGTree ( GTree *treelist )
{
  GtkTreeModel *mod;
  gchar str_buf[64];

  printf("GameviewDisplayGTree...\n");

  mod = gtk_tree_model_filter_get_model(
           GTK_TREE_MODEL_FILTER(gameview_treefilt_model));

//Not calling gtk_tree_model_foreach (mod, GameviewDisplayGTreeItem, treelist) //doesn't seem to show much memory leak... Checkout GameviewDisplayGTreeItem. gtk_tree_model_foreach (mod, GameviewDisplayGTreeItem, treelist);

}

gboolean GameviewDisplayGTreeItem(GtkTreeModel *model,GtkTreePath *path,
                 GtkTreeIter *iter, gpointer treelist)
{
  gchar *char_name;
  gint hide_cnt;

  GString *name;
  GString *value;

   /*############################################*/
   /*##### Memory leaks if I call gtk_tree_store_set many times #####*/
   int i=0;
   for (i=0; i<50; i++)
   {
       printf("GameviewDisplayGTreeItem hide/unhide i: %d\n",i);
      gtk_tree_store_set(GTK_TREE_STORE(model),iter,BOOL_VISIBLE,FALSE,-1);
      gtk_tree_store_set(GTK_TREE_STORE(model),iter,BOOL_VISIBLE,TRUE,-1);
  }
   /*#############################################*/

//   g_string_free (name, TRUE);
//   g_free (char_name);

  return FALSE; //continue traversing.
}





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