Re: GSList and g_filename_from_uri free memory problem



On Thu, Feb 23, 2006 at 09:46:14AM +0100, Colossus wrote:
David Necas (Yeti) wrote:

You have to free it yourself before freeing the list or
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^
individual elements.
   ^^^^^^^^^^^^^^^^^^^

I did it with g_free (filename) but when I use g_print (gslist->data)
I get corrupted results.

filename and gslist->data are pointers to *the same* memory.
When you free the memory -- it does not matter whether you
do g_free(filename) or g_free(gslist->data) -- both pointers
will point to the same freed memory.

GSList can store some untyped pointers.  It has no idea of
what they point to (or if they are real pointers at all),
therefore it cannot make copies of the data, cannot free
them, etc.  It just stores some untyped pointers.

So how to solve the problem ?

Since the problem seems to be an incorrect assumption of how
GSList works and I cannot describe how it actually works more
clearly than above, then either by letting someone with
better English skills to explain it or by you trying harder
to understand me.

Yeti


--
That's enough.



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