[grits] Add grits_object_destroy functions and fix memory leaks
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Add grits_object_destroy functions and fix memory leaks
- Date: Wed, 18 Sep 2013 08:43:12 +0000 (UTC)
commit 67a63167629adc48ff31530dd58ece577f3d7460
Author: Andy Spencer <andy753421 gmail com>
Date: Mon Feb 11 06:12:15 2013 +0000
Add grits_object_destroy functions and fix memory leaks
src/objects/grits-object.c | 7 +++++++
src/objects/grits-object.h | 24 ++++++++++++++++++++++++
src/plugins/elev.c | 3 +--
src/plugins/env.c | 3 +--
src/plugins/map.c | 3 +--
src/plugins/sat.c | 3 +--
src/plugins/test.c | 9 +++------
7 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/src/objects/grits-object.c b/src/objects/grits-object.c
index 2812b9e..55f3975 100644
--- a/src/objects/grits-object.c
+++ b/src/objects/grits-object.c
@@ -172,6 +172,13 @@ void grits_object_set_cursor(GritsObject *object, GdkCursorType cursor)
object->cursor = gdk_cursor_new(cursor);
}
+void grits_object_destroy(GritsObject *object)
+{
+ if (object->viewer)
+ grits_viewer_remove(object->viewer, object);
+ g_object_unref(object);
+}
+
/* Event handling */
void grits_object_pick(GritsObject *object, GritsOpenGL *opengl)
{
diff --git a/src/objects/grits-object.h b/src/objects/grits-object.h
index 728ac72..2c11cd3 100644
--- a/src/objects/grits-object.h
+++ b/src/objects/grits-object.h
@@ -102,6 +102,30 @@ void grits_object_queue_draw(GritsObject *object);
void grits_object_set_cursor(GritsObject *object, GdkCursorType cursor);
/**
+ * grits_object_destroy:
+ * @object: The #GritsObject to destroy
+ *
+ * Removes the widget from it's current viewer (if it has one) and decrements
+ * it's reference count.
+ */
+void grits_object_destroy(GritsObject *object);
+
+/**
+ * grits_object_destroy_pointer:
+ * @object: The pointer to the #GritsObject to destroy
+ *
+ * This functions the same as grits_object_destroy, except that the location of
+ * the object is set to null before proceeding.
+ */
+#define grits_object_destroy_pointer(object) ({ \
+ if (*object) { \
+ GritsObject *tmp = GRITS_OBJECT(*object); \
+ *object = NULL; \
+ grits_object_destroy(tmp); \
+ } \
+})
+
+/**
* grits_object_center:
* @object: The #GritsObject to get the center of
*
diff --git a/src/plugins/elev.c b/src/plugins/elev.c
index 3634df6..f360451 100644
--- a/src/plugins/elev.c
+++ b/src/plugins/elev.c
@@ -272,8 +272,7 @@ static void grits_plugin_elev_dispose(GObject *gobject)
if (LOAD_BIL)
grits_viewer_clear_height_func(viewer);
if (LOAD_TEX)
- grits_viewer_remove(viewer, GRITS_OBJECT(elev->tiles));
- g_object_unref(elev->tiles);
+ grits_object_destroy_pointer(&elev->tiles);
g_object_unref(viewer);
}
G_OBJECT_CLASS(grits_plugin_elev_parent_class)->dispose(gobject);
diff --git a/src/plugins/env.c b/src/plugins/env.c
index 658881d..717e9d7 100644
--- a/src/plugins/env.c
+++ b/src/plugins/env.c
@@ -375,8 +375,7 @@ static void grits_plugin_env_dispose(GObject *gobject)
/* Drop references */
if (env->viewer) {
for (GList *cur = env->refs; cur; cur = cur->next)
- grits_viewer_remove(env->viewer, cur->data);
- g_list_free_full(env->refs, g_object_unref);
+ grits_object_destroy_pointer(&cur->data);
g_object_unref(env->viewer);
g_object_unref(env->prefs);
glDeleteTextures(1, &env->tex);
diff --git a/src/plugins/map.c b/src/plugins/map.c
index 23e8b24..b9a5495 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -194,8 +194,7 @@ static void grits_plugin_map_dispose(GObject *gobject)
//grits_http_abort(map->wms->http);
g_thread_pool_free(map->threads, TRUE, TRUE);
map->viewer = NULL;
- grits_viewer_remove(viewer, GRITS_OBJECT(map->tiles));
- g_object_unref(map->tiles);
+ grits_object_destroy_pointer(&map->tiles);
g_object_unref(viewer);
}
G_OBJECT_CLASS(grits_plugin_map_parent_class)->dispose(gobject);
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index bf3b598..a57277d 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -173,8 +173,7 @@ static void grits_plugin_sat_dispose(GObject *gobject)
grits_http_abort(sat->wms->http);
g_thread_pool_free(sat->threads, TRUE, TRUE);
sat->viewer = NULL;
- grits_viewer_remove(viewer, GRITS_OBJECT(sat->tiles));
- g_object_unref(sat->tiles);
+ grits_object_destroy_pointer(&sat->tiles);
g_object_unref(viewer);
}
G_OBJECT_CLASS(grits_plugin_sat_parent_class)->dispose(gobject);
diff --git a/src/plugins/test.c b/src/plugins/test.c
index 2c3e52f..8d12dc1 100644
--- a/src/plugins/test.c
+++ b/src/plugins/test.c
@@ -177,12 +177,9 @@ static void grits_plugin_test_dispose(GObject *_test)
if (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(test->marker);
- g_object_unref(test->poly);
- g_object_unref(test->line);
+ grits_object_destroy_pointer(&test->marker);
+ grits_object_destroy_pointer(&test->poly);
+ grits_object_destroy_pointer(&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]