Re: problem



Hi,

Anthony Ferrand <Anthony-Ferrand wanadoo fr> writes:

> here is a selected part of my code:
> ------------------------------------------------
> static void fct2(GtkWidget *entry[])
> {
> gchar *str=malloc(500);
> 
> str=gtk_entry_get_text(GTK_ENTRY(entry[0]));
> printf("str=%s\n",str);<- segfault (of weird string)
> fflush(stdout);
> }

(1) If you work with glib and gtk+, you shouldn't use malloc, but
    g_malloc and g_new instead.
(2) You don't need to allocate any memory for str in this case.
(3) gtk_entry_get_text() returns you a pointer into the GtkEntry
    widget that you should never change or free.

I guess you are seeing a segfault here, because you free'd the
result of gtk_entry_get_text(). 


Salut, Sven




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