a question about g_strconcat()



first, I will show some lines.
[code]
gchar *str_sample = g_strconcat("I have a", "dream that", NULL);

str_sample = g_strconcat(str_sample, " one day", NULL);

str_sample = g_strconcat(str_sample, " we can be friends.", NULL);

// do some work with str_sample

g_free(str_sample);
[/code]

if, for some reasons, I must call g_strconcat() three times, or in
concrete, I must follow some conditions to determine whether should I
concatenate each of the three phrases.... okay, actually, I am writing a
sql query phrase, like this:

if the parameter an_id is a empty string, then I will not append it to the
select phrase.

select * from a_table where 1=1 and `id`='an_id' and `name`='a_name'


actually, I have debug my program and find that each time the str_sample
variable has been assigned a different address. But I'm not sure the
internal mechanism of g_strconcat(), whether it apply for a totally new
space or a space that may overlap with the earlier applied space, if the
latter, then I can't free the earlier applied space, and I think it may
lead to memory leak.


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