From c5e048bd1b0d19198e2a0a9d60ddd58721e8f3d1 Mon Sep 17 00:00:00 2001 From: Wu Xiaotian Date: Tue, 1 Jan 2019 01:53:53 +0800 Subject: Fix the runtime warning about gtk_widget_destroy. --- libslab/tile.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'libslab') diff --git a/libslab/tile.c b/libslab/tile.c index 9d628f8b..712a61dc 100644 --- a/libslab/tile.c +++ b/libslab/tile.c @@ -35,6 +35,7 @@ typedef struct } TilePrivate; static void tile_finalize (GObject *); +static void tile_dispose (GObject *); static void tile_get_property (GObject *, guint, GValue *, GParamSpec *); static void tile_set_property (GObject *, guint, const GValue *, GParamSpec *); static GObject *tile_constructor (GType, guint, GObjectConstructParam *); @@ -92,6 +93,7 @@ tile_class_init (TileClass * this_class) g_obj_class->get_property = tile_get_property; g_obj_class->set_property = tile_set_property; g_obj_class->finalize = tile_finalize; + g_obj_class->dispose = tile_dispose; widget_class->focus_in_event = tile_focus_in; widget_class->focus_out_event = tile_focus_out; @@ -175,25 +177,44 @@ tile_finalize (GObject * g_object) if (tile->n_actions) /* this will also free "default_action" entry */ { - gint x; - for (x = 0; x < tile->n_actions; x++) - { - if (tile->actions[x]) - g_object_unref (tile->actions[x]); - } g_free (tile->actions); } if (tile->uri) g_free (tile->uri); - if (tile->context_menu) - gtk_widget_destroy (GTK_WIDGET (tile->context_menu)); g_object_unref (priv->double_click_detector); (*G_OBJECT_CLASS (tile_parent_class)->finalize) (g_object); } +static void +tile_dispose (GObject * g_object) +{ + Tile *tile = TILE (g_object); + + /* free the TileAction object */ + if (tile->n_actions) + { + gint x; + for (x = 0; x < tile->n_actions; x++) + { + if (tile->actions[x] != NULL) { + g_object_unref (tile->actions[x]); + tile->actions[x] = NULL; + } + } + } + + /* free the GtkMenu object */ + if (tile->context_menu != NULL) { + gtk_widget_destroy (GTK_WIDGET (tile->context_menu)); + tile->context_menu = NULL; + } + + (*G_OBJECT_CLASS (tile_parent_class)->dispose) (g_object); +} + static void tile_get_property (GObject * g_obj, guint prop_id, GValue * value, GParamSpec * param_spec) { -- cgit v1.2.1