I am a beginner using GTK+ with C to write a small app. I am setting up a filter for GtkTreeView
, with the display func as below, mostly copied from here.
static gboolean filter_func (GtkTreeModel *model, GtkTreeIter *row, gpointer data) {
// if search string is empty return TRUE
gchar *titleId, *region, *name;
gtk_tree_model_get (model, row, 0, &titleId, 1, ®ion, 2, &name, -1);
// get search string
if (strstr (titleId, "search text here") != NULL) {
return TRUE;
}
g_free (titleId);
g_free (region);
g_free (name);
return FALSE;
}
I have assumed so far that free()
is needed with malloc()
and reading https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html tells me:
It's important to match
g_malloc()
(and wrappers such asg_new()
) withg_free()
So if that is the case, then why is g_free()
being called here? The reason why this is important is because this code will be called thousands of times per character typed in the search.