GTree weirdness?



 Folks,

   I'm using GTrees to store some data structures in an application
I'm currently writing.  The data structures are around 0.5 KB in size
and made up mostly of gints, gfloats, and gchar arrays.  The contents
of one of these strings gets used as the key for sorting.  So I have
something like:

typedef struct _FooStruct {
    gint   int1;
    gint   int2;
    gchar  keystring[12];
    gfloat flt1;
    .
    .
    .
    } FooStruct;

   During each iteration around the main loop, certain values can
be set within the structure, one of which flags the structure for
deletion.  This seems like a simple enough procedure, but I keep
getting segfaults that indicate something ain't kosher when I try
to do it.

   The routine that is supposed to clear the structures does a
simple g_tree_traverse() calling a function that checks the value
of the flag in question, and if it checks out, a g_tree_remove()
is done and the data structure which was originally allocated
with g_malloc0() gets g_free()'d.  Within one or two iterations,
I always get a segfault.  Setting MALLOC_CHECK_ to 2 gets me a
call to abort() during the function that actually calls g_free()
on the entry in question.

   I've gone through the code line by line and there are *NO*
other calls to g_free being done on the data structure.  Which
leads to the question: is doing what I'm doing somehow "illegal"
using the GTree API?  Is the simple fact that I'm removing nodes
from the GTree while in the process of a g_tree_traverse() the
cause of my problems?  And if so, how *do* I implement this
selective removal functionality?


thanks,
Jim Wiggs
wiggs wiggs org





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