g_list memory leaks



I've been looking at the GIMP layers_dialog.c code lately, and using it as
a model for some things I've been doing with lists.  One common practice
is to create a GList in a function, and then add it to a GTK list.  Here's
an example from the GIMP code:

void
layers_dialog_update (int gimage_id)
{
  GImage *gimage;
  Layer *layer;
  LayerWidget *lw;
  link_ptr list;
  GList *item_list;

  if (!layersD)
    return;
  if (layersD->gimage_id == gimage_id)
    return;

  layersD->gimage_id = gimage_id;

  suspend_gimage_notify++;

  /*  Free all elements in the layers listbox  */
  gtk_list_clear_items (GTK_LIST (layersD->layer_list), 0, -1);

  list = layersD->layer_widgets;
  while (list)
    {
      lw = (LayerWidget *) list->data;
      list = next_item(list);
      layer_widget_delete (lw);
    }
  layersD->layer_widgets = NULL;

  if (! (gimage = gimage_get_ID (layersD->gimage_id)))
    return;

  /*  Find the preview extents  */
  layers_dialog_preview_extents ();

  layersD->active_layer_id = -1;
  layersD->active_channel_id = -1;
  layersD->floating_sel_id = -1;

  list = gimage->layers;
  item_list = NULL;

  while (list)
    {
      /*  create a layer list item  */
      layer = (Layer *) list->data;
      lw = create_layer_widget (gimage, layer);
      layersD->layer_widgets = append_to_list (layersD->layer_widgets,
lw);
      item_list = g_list_append (item_list, lw->list_item);

      list = next_item (list);
    }

  /*  get the index of the active layer  */
  if (item_list)
    gtk_list_insert_items (GTK_LIST (layersD->layer_list), item_list, 0);

  suspend_gimage_notify--;
}

(Sorry for all the code) Notice that the g_list 'layer_list' is never
freed with g_list_free.  Is this because it is used directly by the
gtk_list, or is it just a memory leek?  Oh, and could someone also explain
the suspend_gimage_notify++/--?

Thanks, Jay

-------------------------------------------
Jay Painter -- jay@ssc.com -- jay@a42.com
Systema Admin., SSC/Linux Journal
http://www.a42.com/~jay



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