Re: Memory question

Allin Cottrell wrote:

gchar *text = g_strdup_printf("banana %d", i);
gtk_entry_set_text(GTK_ENTRY(entry), text);

Is the above code really safe?

You're passing the address of "text" to the function gtk_entry_set_text(). Next you g_free() that address, so AFAIK the memory manager marks it as free. Isn't it dangerous? I mean, after g_free() any call that requests for memory (g_strdup, g_malloc, ...) can overwrite that memory chunk, changing the text in the GtkEntry. Am I right?



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