Fix a variety of memory leaks
authorAndy Spencer <andy753421@gmail.com>
Wed, 26 Dec 2012 08:40:06 +0000 (08:40 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 26 Dec 2012 08:40:55 +0000 (08:40 +0000)
src/grits-opengl.c
src/gtkgl.c
src/objects/grits-tile.c
src/plugins/elev.c
src/plugins/env.c
src/plugins/map.c
src/plugins/sat.c
src/plugins/test.c

index 14515ae..709e6ed 100644 (file)
@@ -587,9 +587,9 @@ static void _objects_free(gpointer value, gpointer _)
 {
        struct RenderLevel *level = value;
        if (level->sorted.next)
-               g_list_free(level->sorted.next);
+               g_list_free_full(level->sorted.next, g_object_unref);
        if (level->unsorted.next)
-               g_list_free(level->unsorted.next);
+               g_list_free_full(level->unsorted.next, g_object_unref);
        g_free(level);
 }
 
@@ -657,6 +657,15 @@ static void grits_opengl_init(GritsOpenGL *opengl)
 static void grits_opengl_dispose(GObject *_opengl)
 {
        g_debug("GritsOpenGL: dispose");
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
+       if (opengl->objects) {
+               GQueue *objects = opengl->objects;;
+               opengl->objects = NULL;
+               g_mutex_lock(&opengl->objects_lock);
+               g_queue_foreach(objects, _objects_free, NULL);
+               g_queue_free(objects);
+               g_mutex_unlock(&opengl->objects_lock);
+       }
        G_OBJECT_CLASS(grits_opengl_parent_class)->dispose(_opengl);
 }
 static void grits_opengl_finalize(GObject *_opengl)
@@ -664,10 +673,9 @@ static void grits_opengl_finalize(GObject *_opengl)
        g_debug("GritsOpenGL: finalize");
        GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        roam_sphere_free(opengl->sphere);
-       g_queue_foreach(opengl->objects, _objects_free, NULL);
-       g_queue_free(opengl->objects);
        g_mutex_clear(&opengl->objects_lock);
        g_mutex_clear(&opengl->sphere_lock);
+       gtk_gl_disable(GTK_WIDGET(opengl));
        G_OBJECT_CLASS(grits_opengl_parent_class)->finalize(_opengl);
 }
 static void grits_opengl_class_init(GritsOpenGLClass *klass)
index af2c62b..8808ed5 100644 (file)
@@ -112,6 +112,8 @@ void gtk_gl_enable(GtkWidget *widget)
        GdkVisual   *visual = gdk_x11_screen_lookup_visual(screen, xvinfo->visualid);
        GdkColormap *cmap   = gdk_colormap_new(visual, FALSE);
        gtk_widget_set_colormap(widget, cmap);
+       g_object_unref(cmap);
+       XFree(xvinfo);
 
        /* Disable GTK double buffering */
        gtk_widget_set_double_buffered(widget, FALSE);
index b566e33..6ea70f8 100644 (file)
@@ -39,7 +39,7 @@
 #include "gtkgl.h"
 #include "grits-tile.h"
 
-guint  grits_tile_mask = 0;
+static guint  grits_tile_mask = 0;
 
 gchar *grits_tile_path_table[2][2] = {
        {"00.", "01."},
@@ -364,6 +364,7 @@ static guint _grits_tile_load_mask(void)
 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+       g_free(bytes);
        return tex;
 }
 
index 92d8dd1..d359d1d 100644 (file)
@@ -286,7 +286,6 @@ GritsPluginElev *grits_plugin_elev_new(GritsViewer *viewer)
        elev->viewer = g_object_ref(viewer);
 
        /* Load initial tiles */
-       _load_tile(elev->tiles, elev);
        _update_tiles(NULL, elev);
 
        /* Connect signals */
@@ -340,6 +339,8 @@ static void grits_plugin_elev_dispose(GObject *gobject)
                        grits_viewer_clear_height_func(viewer);
                if (LOAD_TEX)
                        grits_viewer_remove(viewer, GRITS_OBJECT(elev->tiles));
+               else
+                       g_object_unref(elev->tiles);
                soup_session_abort(elev->wms->http->soup);
                g_thread_pool_free(elev->threads, TRUE, TRUE);
                while (gtk_events_pending())
index 8b16466..d833b43 100644 (file)
@@ -378,6 +378,7 @@ static void grits_plugin_env_dispose(GObject *gobject)
                        grits_viewer_remove(env->viewer, cur->data);
                g_list_free(env->refs);
                g_object_unref(env->viewer);
+               g_object_unref(env->prefs);
                glDeleteTextures(1, &env->tex);
                env->viewer = NULL;
        }
index 72fb320..c57bae8 100644 (file)
@@ -189,7 +189,6 @@ GritsPluginMap *grits_plugin_map_new(GritsViewer *viewer)
        map->viewer = g_object_ref(viewer);
 
        /* Load initial tiles */
-       _load_tile(map->tiles, map);
        _update_tiles(NULL, map);
 
        /* Connect signals */
index c96ecc4..9b10a2d 100644 (file)
@@ -173,7 +173,6 @@ GritsPluginSat *grits_plugin_sat_new(GritsViewer *viewer)
        sat->viewer = g_object_ref(viewer);
 
        /* Load initial tiles */
-       _load_tile(sat->tiles, sat);
        _update_tiles(NULL, sat);
 
        /* Connect signals */
index a463d3a..8a7e8a6 100644 (file)
@@ -175,11 +175,12 @@ static void grits_plugin_test_dispose(GObject *_test)
        g_debug("GritsPluginTest: dispose");
        GritsPluginTest *test = GRITS_PLUGIN_TEST(_test);
        if (test->viewer) {
-               grits_viewer_remove(test->viewer, GRITS_OBJECT(test->marker));
-               grits_viewer_remove(test->viewer, GRITS_OBJECT(test->poly));
-               grits_viewer_remove(test->viewer, GRITS_OBJECT(test->line));
-               g_object_unref(test->viewer);
+               GritsViewer *viewer = test->viewer;
                test->viewer = NULL;
+               grits_viewer_remove(viewer, GRITS_OBJECT(test->marker));
+               grits_viewer_remove(viewer, GRITS_OBJECT(test->poly));
+               grits_viewer_remove(viewer, GRITS_OBJECT(test->line));
+               g_object_unref(viewer);
        }
        G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test);
 }