Re: Strange glibc detected invalid pointer with gtk_entry
- From: zz excite it
- To: gtk-app-devel-list gnome org
- Subject: Re: Strange glibc detected invalid pointer with gtk_entry
- Date: Tue, 5 Jul 2011 21:14:03 +0200
On Tuesday 05 July 2011 16:19:00 Emmanuele Bassi wrote:
On 2011-07-05 at 15:05, zz 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.
Cannot imagine glib calling something different than malloc/calloc/realloc at the low level
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?
Ciao,
Tito
ciao,
Emmanuele.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]