Re: Memory question





David Rosal wrote:


Allin Cottrell wrote:

gchar *text = g_strdup_printf("banana %d", i);
gtk_entry_set_text(GTK_ENTRY(entry), text);
g_free(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?


No. gtk_entry_set_text makes a copy.


Cheers,


~david
_______________________________________________
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]