From 49e0f79ffb481d3335f352d99b3ae379a4218b86 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 11 Feb 2012 07:56:05 +0000 Subject: [PATCH] Update GPS plugin reference handling Reference he viewer and prefs at creation and then unref them when it exits. This fixes avoid a double-unref. Also make the dispose function reentrant by setting the viewer field to NULL before unreferencing the viewer. (Dispose may be called recursively by glib when unreferencing other stuff) --- src/plugins/gps-plugin.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/plugins/gps-plugin.c b/src/plugins/gps-plugin.c index 419dc14..befb40e 100644 --- a/src/plugins/gps-plugin.c +++ b/src/plugins/gps-plugin.c @@ -880,8 +880,8 @@ GritsPluginGps *grits_plugin_gps_new(GritsViewer *viewer, GritsPrefs *prefs) /* TODO: move to constructor if possible */ g_debug("GritsPluginGps: new"); GritsPluginGps *gps = g_object_new(GRITS_TYPE_PLUGIN_GPS, NULL); - gps->viewer = viewer; - gps->prefs = prefs; + gps->viewer = g_object_ref(viewer); + gps->prefs = g_object_ref(prefs); initialize_gpsd("localhost", DEFAULT_GPSD_PORT, &gps->gps_data); gps->follow_gps = FALSE; @@ -927,16 +927,15 @@ static void grits_plugin_gps_dispose(GObject *gobject) g_debug("GritsPluginGps: dispose"); if (gps->viewer) { - if (gps->marker) { - grits_viewer_remove(gps->viewer, - GRITS_OBJECT(gps->marker)); - } - g_object_unref(gps->viewer); + GritsViewer *viewer = gps->viewer; gps->viewer = NULL; + if (gps->marker) + grits_viewer_remove(viewer, + GRITS_OBJECT(gps->marker)); + g_object_unref(gps->prefs); + g_object_unref(viewer); } - gps_track_free(&gps->track); - /* Drop references */ G_OBJECT_CLASS(grits_plugin_gps_parent_class)->dispose(gobject); } @@ -948,7 +947,7 @@ static void grits_plugin_gps_finalize(GObject *gobject) g_debug("GritsPluginGps: finalize"); /* Free data */ - gtk_widget_destroy(gps->config); + gps_track_free(&gps->track); G_OBJECT_CLASS(grits_plugin_gps_parent_class)->finalize(gobject); } -- 2.41.0