]> Pileus Git - aweather/commitdiff
Update GPS plugin reference handling
authorAndy Spencer <andy753421@gmail.com>
Sat, 11 Feb 2012 07:56:05 +0000 (07:56 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 12 Feb 2012 07:05:42 +0000 (07:05 +0000)
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

index 419dc1430a13d2970e4b93878c8c4857455acefe..befb40ecb23184088a061d8146d453b5a6a35659 100644 (file)
@@ -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);
        /* 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;
 
        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) {
        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;
                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);
 }
        /* 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 */
        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);
 }
 
        G_OBJECT_CLASS(grits_plugin_gps_parent_class)->finalize(gobject);
 }