free_and_clear() uses free(). g_strdup() requires g_free() (I've encountered crashes mixing them) so just use strdup().