Use grits_object_destroy api and fix memory leaks
authorAndy Spencer <andy753421@gmail.com>
Mon, 11 Feb 2013 06:28:32 +0000 (06:28 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 11 Feb 2013 06:28:32 +0000 (06:28 +0000)
src/plugins/alert.c
src/plugins/gps-plugin.c
src/plugins/level2.c
src/plugins/radar.c

index 3ab84a9..bbdae3f 100644 (file)
@@ -759,10 +759,8 @@ static void _update_warnings(GritsPluginAlert *alert, GList *old)
        /* Remove old messages */
        for (GList *cur = old; cur; cur = cur->next) {
                AlertMsg *msg = cur->data;
-               if (msg->county_based) grits_viewer_remove(alert->viewer,
-                               GRITS_OBJECT(msg->county_based));
-               if (msg->storm_based) grits_viewer_remove(alert->viewer,
-                               GRITS_OBJECT(msg->storm_based));
+               grits_object_destroy_pointer(&msg->county_based);
+               grits_object_destroy_pointer(&msg->storm_based);
        }
 
        /* Add new messages */
@@ -981,13 +979,11 @@ static void grits_plugin_alert_dispose(GObject *gobject)
                alert->viewer = NULL;
                for (GList *cur = alert->msgs; cur; cur = cur->next) {
                        AlertMsg *msg = cur->data;
-                       if (msg->county_based) grits_viewer_remove(viewer,
-                                       GRITS_OBJECT(msg->county_based));
-                       if (msg->storm_based) grits_viewer_remove(viewer,
-                                       GRITS_OBJECT(msg->storm_based));
+                       grits_object_destroy_pointer(&msg->county_based);
+                       grits_object_destroy_pointer(&msg->storm_based);
                }
                for (GList *cur = alert->states; cur; cur = cur->next)
-                       grits_viewer_remove(viewer, cur->data);
+                       grits_object_destroy_pointer(&cur->data);
                gtk_widget_destroy(alert->details);
                g_object_unref(alert->prefs);
                g_object_unref(viewer);
index fe693e3..f91382d 100644 (file)
@@ -514,11 +514,7 @@ gboolean gps_redraw_all(gpointer data)
                gps_track_add_point(&gps->track,
                          gps_data->fix.latitude, gps_data->fix.longitude, 0.0);
 
-               if (gps->track.line) {
-                       grits_viewer_remove(gps->viewer,
-                           GRITS_OBJECT(gps->track.line));
-                       gps->track.line = NULL;
-               }
+               grits_object_destroy_pointer(&gps->track.line);
 
                gps->track.line = grits_line_new(gps->track.points);
                gps->track.line->color[0]  = 1.0;
@@ -533,11 +529,7 @@ gboolean gps_redraw_all(gpointer data)
        }
 
        if (gps_data_is_valid(gps_data)) {
-               if (gps->marker) {
-                       grits_viewer_remove(gps->viewer,
-                           GRITS_OBJECT(gps->marker));
-                       gps->marker = NULL;
-               }
+               grits_object_destroy_pointer(&gps->marker);
 
                gchar *path = find_path(GPS_MARKER_ICON_PATH, GPS_MARKER_ICON);
                if (path) {
@@ -949,9 +941,7 @@ static void grits_plugin_gps_dispose(GObject *gobject)
        if (gps->viewer) {
                GritsViewer *viewer = gps->viewer;
                gps->viewer = NULL;
-               if (gps->marker)
-                       grits_viewer_remove(viewer,
-                              GRITS_OBJECT(gps->marker));
+               grits_object_destroy_pointer(&gps->marker);
                g_object_unref(gps->prefs);
                g_object_unref(viewer);
        }
index 2f595c9..585c460 100644 (file)
@@ -523,11 +523,7 @@ static void aweather_level2_dispose(GObject *_level2)
 {
        AWeatherLevel2 *level2 = AWEATHER_LEVEL2(_level2);
        g_debug("AWeatherLevel2: dispose - %p", _level2);
-       if (level2->volume) {
-               grits_viewer_remove(GRITS_OBJECT(level2->volume)->viewer,
-                               GRITS_OBJECT(level2->volume));
-               level2->volume = NULL;
-       }
+       grits_object_destroy_pointer(&level2->volume);
        G_OBJECT_CLASS(aweather_level2_parent_class)->dispose(_level2);
 }
 static void aweather_level2_finalize(GObject *_level2)
index 560adc8..50c66a8 100644 (file)
@@ -218,10 +218,7 @@ void _site_update(RadarSite *site)
 
        /* Remove old volume */
        g_debug("RadarSite: update - remove - %s", site->city->code);
-       if (site->level2) {
-               grits_viewer_remove(site->viewer, GRITS_OBJECT(site->level2));
-               site->level2 = NULL;
-       }
+       grits_object_destroy_pointer(&site->level2);
 
        /* Fork loading right away so updating the
         * list of times doesn't take too long */
@@ -249,10 +246,7 @@ void radar_site_unload(RadarSite *site)
                gtk_widget_destroy(site->config);
 
        /* Remove radar */
-       if (site->level2) {
-               grits_viewer_remove(site->viewer, GRITS_OBJECT(site->level2));
-               site->level2 = NULL;
-       }
+       grits_object_destroy_pointer(&site->level2);
 
        site->status = STATUS_UNLOADED;
 }
@@ -355,7 +349,7 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
 void radar_site_free(RadarSite *site)
 {
        radar_site_unload(site);
-       grits_viewer_remove(site->viewer, GRITS_OBJECT(site->marker));
+       grits_object_destroy_pointer(&site->marker);
        if (site->location_id)
                g_signal_handler_disconnect(site->viewer, site->location_id);
        grits_http_free(site->http);
@@ -626,11 +620,8 @@ void radar_conus_free(RadarConus *conus)
        if (conus->idle_source)
                g_source_remove(conus->idle_source);
 
-       for (int i = 0; i < 2; i++) {
-               GritsTile *tile = conus->tile[i];
-               grits_viewer_remove(conus->viewer, GRITS_OBJECT(tile));
-               g_object_unref(tile);
-       }
+       for (int i = 0; i < 2; i++)
+               grits_object_destroy_pointer(&conus->tile[i]);
 
        g_object_unref(conus->viewer);
        g_free(conus);
@@ -812,11 +803,10 @@ static void grits_plugin_radar_dispose(GObject *gobject)
                GritsViewer *viewer = self->viewer;
                self->viewer = NULL;
                g_signal_handler_disconnect(self->config, self->tab_id);
-               grits_viewer_remove(viewer, GRITS_OBJECT(self->hud));
+               grits_object_destroy_pointer(&self->hud);
                radar_conus_free(self->conus);
                g_hash_table_destroy(self->sites);
                g_object_unref(self->config);
-               g_object_unref(self->hud);
                g_object_unref(self->prefs);
                g_object_unref(viewer);
        }