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

freeing glist ->data problem




Hi, 
I'm stuck with a problem with glists. 
I was looking for memory leaks in a program I was doing to learn gnome,
gtk ,etc and I've noticed that whenever I put my structures in a glist
there's no way to free them. The program report no errors but a "free" in
other terminal shows the memory stuck. If I change the container to a 
static array the problem dissapears. I've tested the addresses being freed
and are the same as the ones being allocated. If anyboby has any ideas
about what it's causing it:

------------------------ prova3.c ---------------------------------------
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <glib.h>

#define DEB_LOOP 10000


GList  *create_glist(gint *i) {
  GList *l=NULL;
  gint j;
    for (j=0;j<20;j++)       
        l = g_list_prepend(l, g_strdup_printf("Cronline: %d\n", (*i)++));

    return l;
}

int
main (int argc, char *argv[])
{
  gint i, lin;

  GList *l[DEB_LOOP];
  GList *laux;
  gchar s[80];
  gint j = 0;
           

        for (i = lin = 0 ; i < DEB_LOOP; i++) {
	      l[i] = create_glist(&lin);
	    }
  	   printf ("\n---   I got memory  -------\n");
           printf ("\nPress key to free");
	   scanf("%s",s);
	  for ( i = 0; i < DEB_LOOP; i++) {
              for (laux = l[i]; laux !=NULL; laux = g_list_next(laux)) {
                  g_free( laux->data);
	     }
             g_list_free (l[i]);
           }

  	   printf ("\n---   Memory free?  -------\n");
           printf ("Press key to end");
	   scanf("%s",s);

  return 0;
}
------------------------------------end of program -----------------

PS: I've reproduced the problem with glib 1.2.0 in a Debian system and
with glib 1.2.6 in a Mandrake one





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