[grits] Fix a variety of memory leaks
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Fix a variety of memory leaks
- Date: Mon, 21 Jan 2013 05:24:17 +0000 (UTC)
commit 8594927c0cd07daea95e8b99dc36ffef4f12da8a
Author: Andy Spencer <andy753421 gmail com>
Date: Wed Dec 26 08:40:06 2012 +0000
Fix a variety of memory leaks
src/grits-opengl.c | 16 ++++++++++++----
src/gtkgl.c | 2 ++
src/objects/grits-tile.c | 3 ++-
src/plugins/elev.c | 3 ++-
src/plugins/env.c | 1 +
src/plugins/map.c | 1 -
src/plugins/sat.c | 1 -
src/plugins/test.c | 9 +++++----
8 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/src/grits-opengl.c b/src/grits-opengl.c
index 14515ae..709e6ed 100644
--- a/src/grits-opengl.c
+++ b/src/grits-opengl.c
@@ -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)
diff --git a/src/gtkgl.c b/src/gtkgl.c
index af2c62b..8808ed5 100644
--- a/src/gtkgl.c
+++ b/src/gtkgl.c
@@ -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);
diff --git a/src/objects/grits-tile.c b/src/objects/grits-tile.c
index b566e33..6ea70f8 100644
--- a/src/objects/grits-tile.c
+++ b/src/objects/grits-tile.c
@@ -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;
}
diff --git a/src/plugins/elev.c b/src/plugins/elev.c
index 92d8dd1..d359d1d 100644
--- a/src/plugins/elev.c
+++ b/src/plugins/elev.c
@@ -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())
diff --git a/src/plugins/env.c b/src/plugins/env.c
index 8b16466..d833b43 100644
--- a/src/plugins/env.c
+++ b/src/plugins/env.c
@@ -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;
}
diff --git a/src/plugins/map.c b/src/plugins/map.c
index 72fb320..c57bae8 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -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 */
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index c96ecc4..9b10a2d 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -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 */
diff --git a/src/plugins/test.c b/src/plugins/test.c
index a463d3a..8a7e8a6 100644
--- a/src/plugins/test.c
+++ b/src/plugins/test.c
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]