Re: Does g_key_file_free() free pointers from g_key_file_get_string()?



On Fri, Jun 17, 2011 at 12:19 AM, Kris Bahnsen
<nevrgonastopme00 gmail com> wrote:
> Working on a project and encountered g_key_file for the first time.  I have
> a question with the API, what happens to strings returned by
> g_key_file_get_string? Are they freed when you free the key_file? Are they
> just magically garbage collected? Must they be freed manually?  What got me
> asking this is the verbiage of the API:
> g_key_file_get_string()
> "Returns: a newly allocated string or NULL if the specified key cannot be
> found"
> While g_strndup() says"
> "Returns: a newly-allocated buffer containing the first n bytes of str,
> nul-terminated"
> g_strndup() description explicitly says that the return value should be
> freed when no longer needed, but g_key_file_get_string() says no such thing.
>  I was unable to find any write-up describing the difference between a
> "string" or a "buffer" in the sense of the return value of either of those
> two functions.  Both returns are of type gchar *.  Thanks for any
> clarification you can provide.
> -Kris

Since the documentation says it's a newly allocated string, I have
always freed the string when I no longer need it. This hasn't produced
any ill effects so far. Usually, valgrind will catch problems related
to freeing pointers to non-heap memory.
-Jim


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