Re: g_locale_to_utf8



Who is losing which pointer?

g_locale_to_utf8 returns the UTF-8 string in an allocated buffer. It's the API user's responsibility to do the clean-up. s is receiving such a buffer from g_locale_to_utf8 and hence must be freed, after you're done with using s, in this example, the only use is the gprintf.

If the intention is to use 's' further in the code, then obviously it shouldn't be freed now, but should be freed sometime later, when you're done with using it.

Look at the sources, there is a g_malloc being done for the string to return, and it isn't being freed anywhere.

-vc

----- Original Message ----- From: "Hubert Sokolowski" <h sokolowski wsisiz edu pl>
To: "Viraj Chatterjee" <vchatter adobe com>
Cc: <gtk-app-devel-list gnome org>
Sent: Monday, January 10, 2005 2:59 PM
Subject: Re: g_locale_to_utf8


Second version but with modifications...

g_free(string); // free memory returned in g_strdup
g_free(s); // free memory returned in g_locale_to_utf8

you are wrong, this is wrong since you are loosing the pointer to a newly
allocated buffer allocated by g_locate_to_utf8, that you should free.


-vc

----- Original Message -----
From: "Andreas Volz" <lists brachttal net>
To: <gtk-app-devel-list gnome org>
Sent: Monday, January 10, 2005 2:46 PM
Subject: g_locale_to_utf8


Hi,

I've a question how to use the return of the g_locale_to_utf8 function.
For example I've this code:

----------------------
gchar *s;
gchar *string;

string = g_strdup ("hallo");

s = g_locale_to_utf8 (string,-1,0,0,0);
g_print ("%s\n", s);
free (string);
-----------------------

Or should I do:

...
s = g_strdup (g_locale_to_utf8 (string,-1,0,0,0));
g_print ("%s\n", s);
free (string);
free (s);

As I think it's the second version, but I'm not sure. Can you help me?

regards
Andreas
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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