Re: Memory question



On Tue, 27 Sep 2005, David Rosal wrote:

I know this is a general C programming issue, but...

It is a memory leak to call g_strdup() as argument to other function?

For example, if I do this:

gtk_entry_set_text(GTK_ENTRY(entry), g_strdup("banana");

Am I leaking memory?

Yes, since the allocated string will not be freed by gtk_entry_set_text().

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

Allin Cottrell



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