The comment already identified the issue (you are inserting a pointer to a local stack variable into the tree), but there are still a few less serious issues. When storing int
in a GTree
, it's better to use it as the pointer value directly, e.g.:
gboolean iter_all(gpointer key, gpointer value, gpointer data) {
int s = (int) value;
printf("\n%s%d \n", (char *)key, s);
return FALSE;
}
...
g_tree_insert(tree, (gpointer) g_strdup(p1), (gpointer) p2);
To avoid memory leaks, you also need to specify a destroy function to free the string keys:
GTree* t = g_tree_new_full((GCompareFunc) g_ascii_strcasecmp,
NULL, g_free, NULL);