how to free the memory malloced?



Hello everyone:
  I want to know how to free the malloced memory used in a g_list?
 
here is my code
 
 
#include <stdio.h>
#include <stdlib.h>
 
#include <glib.h>
 
typedef struct
{
  char buf1[128];
  char buf2[128];
  char buf3[128];
}
buf;
 

void
freenode (gpointer data, gpointer userdata)
{
  //static int i = 0;
  //printf("%d\n", ++i);
  //free (data);
  return;
 
//  free(data);
}
 
int
main ()
{
  int i, j;
  buf *tmp;
  GList *head = NULL;
 
  for (j = 0; j < 2000; j++)
    {
      for (i = 0; i < 2000; i++)
        {
          tmp = (buf *) malloc (sizeof (buf));
          head = g_list_append (head, tmp);
        }
 
      g_list_foreach (head, freenode, NULL);
 
      g_list_free (head);
 
    }
  return 0;
}


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