Re: g_locale_to_utf8

On Monday 10 January 2005 10:25, shakti wrote:

You have to free the return value of g_strdup() but not the return value
of g_locale_to_utf8() function.

Have a look at:

You are misreading the API here. Both functions return newly-allocated 
strings, and in both cases you have to g_free() the returned string when you 
don't need it any longer.

Just because the g_locale_to_utf8() docs don't tell you explicitly that the 
return value needs to be freed doesn't mean that you don't have to free it; 
it's implicit in the type of the return value. 

As a general rule: if a GLib string function returns a const gchar * then you 
do not have to free it and must not modify it. If a GLib string function 
returns a gchar *, then you have to free this string later.


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