RE: freeing GTK+ memory



On Sun, 2008-10-26 at 16:23 -0700, Ian Puleston wrote:
> The documentation for gtk_radio_button_get_group() says that it
> returns a GSList*, but is that a list that it allocated for me so I
> will need to free it, or is it a pointer to an internal GSList that I
> must not free? A call to g_slist_free() didn't break anything

Note that the fact that g_slist_free() didn't break anything doesn't
prove that the code is correct.  In case of a double free, the breakage
could still occur at an unrelated point later.
gtk_radio_button_get_group() amounts to:

GSList*
gtk_radio_button_get_group (GtkRadioButton *radio_button)
{
  g_return_val_if_fail (GTK_IS_RADIO_BUTTON (radio_button), NULL);

  return radio_button->group;
}

which indicates that you don't get a fresh list.

> so presumably that's the correct thing to do, but "try it and see"
> like that is not really the ideal way to design an app.

With GTK+ you also have the option of inspecting the source code.
Admittedly not the most pleasant option and in some cases equally
misleading because it leads to confusion between the interface than the
implementation, but in any case more robust than "try it and see".



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