libgnt/libgnt

Make all destroy functions multi-call safe.

2020-09-27, Elliott Sales de Andrade
ffb6069167a2
Parents d644d6c0aafa
Children d9dbe0d9d065
Make all destroy functions multi-call safe.

Also, fix an incorrect name for a dispose vfunc.

Testing Done:
Compile only, and the test from LIBGNT-11.

Reviewed at https://reviews.imfreedom.org/r/141/
  • +1 -1
    gntbutton.c
  • +9 -6
    gntentry.c
  • +3 -2
    gntfilesel.c
  • +1 -1
    gntlabel.c
  • +1 -0
    gntmenu.c
  • +5 -8
    gntmenuitem.c
  • +8 -2
    gnttextview.c
  • +1 -2
    gntwindow.c
  • +1 -1
    gntws.c
  • --- a/gntbutton.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntbutton.c Sun Sep 27 21:30:55 2020 -0500
    @@ -111,7 +111,7 @@
    GntButton *button = GNT_BUTTON(widget);
    GntButtonPrivate *priv = gnt_button_get_instance_private(button);
    - g_free(priv->text);
    + g_clear_pointer(&priv->text, g_free);
    }
    static gboolean
    --- a/gntentry.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntentry.c Sun Sep 27 21:30:55 2020 -0500
    @@ -1010,25 +1010,28 @@
    {
    GntEntry *entry = GNT_ENTRY(widget);
    GntEntryPrivate *priv = gnt_entry_get_instance_private(entry);
    - g_free(priv->start);
    +
    + g_clear_pointer(&priv->start, g_free);
    if (priv->history) {
    - priv->history = g_list_first(priv->history);
    - g_list_free_full(priv->history, g_free);
    + g_list_free_full(g_list_first(priv->history), g_free);
    + priv->history = NULL;
    }
    if (priv->suggests) {
    g_list_free_full(priv->suggests, g_free);
    + priv->suggests = NULL;
    }
    if (priv->ddown) {
    gnt_widget_destroy(gnt_widget_get_parent(priv->ddown));
    + priv->ddown = NULL;
    }
    - g_free(priv->search->needle);
    - g_free(priv->search);
    + g_clear_pointer(&priv->search->needle, g_free);
    + g_clear_pointer(&priv->search, g_free);
    - jail_killring(priv->killring);
    + g_clear_pointer(&priv->killring, jail_killring);
    }
    static void
    --- a/gntfilesel.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntfilesel.c Sun Sep 27 21:30:55 2020 -0500
    @@ -82,10 +82,11 @@
    GntFileSel *sel = GNT_FILE_SEL(widget);
    GntFileSelPrivate *priv = gnt_file_sel_get_instance_private(sel);
    - g_free(priv->current);
    - g_free(priv->suggest);
    + g_clear_pointer(&priv->current, g_free);
    + g_clear_pointer(&priv->suggest, g_free);
    if (priv->tags) {
    g_list_free_full(priv->tags, g_free);
    + priv->tags = NULL;
    }
    }
    --- a/gntlabel.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntlabel.c Sun Sep 27 21:30:55 2020 -0500
    @@ -55,7 +55,7 @@
    gnt_label_destroy(GntWidget *widget)
    {
    GntLabel *label = GNT_LABEL(widget);
    - g_free(label->text);
    + g_clear_pointer(&label->text, g_free);
    }
    static void
    --- a/gntmenu.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntmenu.c Sun Sep 27 21:30:55 2020 -0500
    @@ -414,6 +414,7 @@
    {
    GntMenu *menu = GNT_MENU(widget);
    g_list_free_full(menu->list, g_object_unref);
    + menu->list = NULL;
    org_destroy(widget);
    }
    --- a/gntmenuitem.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntmenuitem.c Sun Sep 27 21:30:55 2020 -0500
    @@ -59,17 +59,14 @@
    *****************************************************************************/
    static void
    -gnt_menuitem_destroy(GObject *obj)
    +gnt_menuitem_dispose(GObject *obj)
    {
    GntMenuItem *item = GNT_MENU_ITEM(obj);
    GntMenuItemPrivate *priv = gnt_menuitem_get_instance_private(item);
    - g_free(priv->text);
    - priv->text = NULL;
    - if (priv->submenu) {
    - gnt_widget_destroy(GNT_WIDGET(priv->submenu));
    - }
    - g_free(priv->id);
    + g_clear_pointer(&priv->text, g_free);
    + g_clear_pointer((GntWidget **)&priv->submenu, gnt_widget_destroy);
    + g_clear_pointer(&priv->id, g_free);
    G_OBJECT_CLASS(gnt_menuitem_parent_class)->dispose(obj);
    }
    @@ -79,7 +76,7 @@
    {
    GObjectClass *obj_class = G_OBJECT_CLASS(klass);
    - obj_class->dispose = gnt_menuitem_destroy;
    + obj_class->dispose = gnt_menuitem_dispose;
    signals[SIG_ACTIVATE] =
    g_signal_new("activate",
    --- a/gnttextview.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gnttextview.c Sun Sep 27 21:30:55 2020 -0500
    @@ -245,10 +245,16 @@
    gnt_text_view_destroy(GntWidget *widget)
    {
    GntTextView *view = GNT_TEXT_VIEW(widget);
    - view->list = g_list_first(view->list);
    - g_list_free_full(view->list, (GDestroyNotify)free_text_line);
    +
    + g_list_free_full(g_list_first(view->list),
    + (GDestroyNotify)free_text_line);
    + view->list = NULL;
    +
    g_list_free_full(view->tags, (GDestroyNotify)free_tag);
    + view->tags = NULL;
    +
    g_string_free(view->string, TRUE);
    + view->string = NULL;
    }
    static char *
    --- a/gntwindow.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntwindow.c Sun Sep 27 21:30:55 2020 -0500
    @@ -74,8 +74,7 @@
    GntWindow *window = GNT_WINDOW(widget);
    GntWindowPrivate *priv = gnt_window_get_instance_private(window);
    - if (priv->menu)
    - gnt_widget_destroy(GNT_WIDGET(priv->menu));
    + g_clear_pointer((GntWidget **)&priv->menu, gnt_widget_destroy);
    g_clear_pointer(&priv->accels, g_hash_table_destroy);
    org_destroy(widget);
    --- a/gntws.c Sun Sep 27 17:46:39 2020 -0500
    +++ b/gntws.c Sun Sep 27 21:30:55 2020 -0500
    @@ -72,7 +72,7 @@
    GntWS *ws = GNT_WS(obj);
    GntWSPrivate *priv = gnt_ws_get_instance_private(ws);
    - g_free(priv->name);
    + g_clear_pointer(&priv->name, g_free);
    }
    static void