Re: Does g_key_file_free() free pointers from g_key_file_get_string()?
- From: Jim George <jimgeorge gmail com>
- To: Kris Bahnsen <nevrgonastopme00 gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Does g_key_file_free() free pointers from g_key_file_get_string()?
- Date: Fri, 17 Jun 2011 00:24:31 -0600
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:
> "Returns: a newly allocated string or NULL if the specified key cannot be
> While g_strndup() says"
> "Returns: a newly-allocated buffer containing the first n bytes of str,
> 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.
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.
] [Thread Prev