Sidharth N. Kashyap
Sidharth N. Kashyap

Reputation: 309

GList Behaviour Error - invalid next size (normal)

I was using Gnome libglib for one of my projects and encountered a weird error. The number of elements that I can enter into a GList looks to be limited to 45. At the 45th element, it gives this error

40 counter
41 counter
42 counter
43 counter
44 counter
45 counter
*** Error in `./a.out': free(): invalid next size (normal):   0x0000000001be7e00 ***
Aborted (core dumped)

Here is the function that produces this error

`GList* getMeAGlist(int size)
{
    GList* test = NULL;

    printf("%d\n",size);
    for(int i=0;i<size;i++)
    {
        printf("%d counter\n",i);
        test  = g_list_append(test,NULL);
    }
    return test;
}`    

Highly appreciate your help.

Upvotes: 0

Views: 98

Answers (1)

Jussi Kukkonen
Jussi Kukkonen

Reputation: 14607

The code you included looks fine and GLib doesn't have a limitation like this: I can easily call your function with 100000 as the argument and it works (I didn't try with a larger number only because using g_list_append() is slow with large lists).

From the error message I'm guessing you are trying to call free() on something that isn't allocated with malloc() and friends or is already freed. Have you tried the above function without any other code -- just a main() that calls your function and returns?

Upvotes: 1

Related Questions