hi; On 5 July 2011 20:14, <z...@excite.it> wrote: > On Tuesday 05 July 2011 16:19:00 Emmanuele Bassi wrote: >> On 2011-07-05 at 15:05, z...@excite.it wrote: >> > void my_gtk_entry_set_text(GtkEntry *entry, char *data) >> > { >> > char *tmp; >> > >> > if (!data) data = ""; >> > >> > if (g_utf8_validate(data, -1, NULL) != TRUE) { >> > tmp = g_locale_to_utf8(data, -1, NULL, NULL, NULL); >> > gtk_entry_set_text(entry, tmp); >> > xfree(&tmp); >> ^^^^^^^^^^^^ >> >> agh! >> >> g_locale_to_utf8() returns memory allocated through the GLib API; you >> need to call g_free() to free it. *do not* mix GLib's memory allocation >> functions with other allocation functions. > > Hi, > to be honest :-) I'm doing this for a long time and never experienced > problems.
sheer luck. > Cannot imagine glib calling something different than malloc/calloc/realloc at > the low level they might, but the allocation/deallocation functions can be replaced: http://developer.gnome.org/glib/stable/glib-Memory-Allocation.html > so unless there are some special profiler or debug functions free should be > ok or at least > it for me worked flawlessly in linux and windows. I think there must be more > than a simple no-no. > Thanks for your hint will try to correct this bad habit in the future. > To fix my code a simple > > #define malloc g_malloc > #define free g_free > #define calloc g_calloc > #define realloc g_realloc > > should do it. Right? no, don't do that. it's awful, and it'll mask debugging and compiler warnings. just fix the code; the 5 minutes of work will avoid issues further down the road. ciao, Emmanuele. -- W: http://www.emmanuelebassi.name B: http://blogs.gnome.org/ebassi/ _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list