C/Glib Strings that should be freed by the caller
c, glib
Solution
Yes it is necessary to free the string returned by `function1`. To allow you to do this, you need to take a copy of the return value :-
gchar* temp = function1("something");
gchar* string = function2(temp);
g_free(temp);
g_free(string);
Problem
I am using glib, it has a lot of functions that return strings that should be freed myself. Can I, pass these functions to other functions? Example: function1 returns a string that must be freed for the caller. function2 returns a pointer to a string that must be freed also. ``` gchar *string = function2(function1("something")); g_free (string); ``` How should I free the string returned from function1? Is this necessary? Thanks a lot, and sorry for my english