Re: a question about g_strconcat()



g_strconcat() ALWAYS returns newly allocated memory on each call. Most
likely you will have leak when you code like that, because you lost
reference. You have to assign it to a new pointer such as:

gchar *ptr1 = g_strconcat ("ptr1", NULL);
gchar *ptr2 = g_strconcat (ptr1, "ptr2", NULL);
gchar *ptr3 = g_strconcat (ptr2, "ptr3", NULL);
...
g_free(ptr1); g_free(ptr2); g_free(ptr3);

Have a look g_strconcat() function here
http://git.gnome.org/browse/glib/tree/glib/gstrfuncs.c#n549

Why not use formatting function such as g_strdup_printf() instead?
Also play with GString.


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