[grits] More reference counting updates
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] More reference counting updates
- Date: Mon, 21 Jan 2013 05:24:32 +0000 (UTC)
commit 618983b0bfdc9af2d6dc368570a1911b892b5166
Author: Andy Spencer <andy753421 gmail com>
Date: Wed Dec 26 23:39:12 2012 +0000
More reference counting updates
The viewer now adds it's own references and doesn't take references from
the caller. In almost all cases the caller needs to keep it's reference
so that it can remove the object when the plugin is unloaded.
src/grits-opengl.c | 5 +++++
src/grits-plugin.c | 2 +-
src/grits-viewer.c | 2 --
src/objects/grits-callback.c | 1 +
src/plugins/elev.c | 3 +--
src/plugins/env.c | 2 +-
src/plugins/map.c | 1 +
src/plugins/sat.c | 1 +
src/plugins/test.c | 3 +++
9 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/src/grits-opengl.c b/src/grits-opengl.c
index 49a9c53..a17ddda 100644
--- a/src/grits-opengl.c
+++ b/src/grits-opengl.c
@@ -618,6 +618,7 @@ static void grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
list->next->prev = link;
list->next = link;
object->ref = link;
+ g_object_ref(object);
g_mutex_unlock(&opengl->objects_lock);
}
@@ -625,6 +626,8 @@ void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
{
g_assert(GRITS_IS_OPENGL(_opengl));
GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
+ if (!object->ref)
+ return;
g_mutex_lock(&opengl->objects_lock);
GList *link = object->ref;
/* Just unlink and free it, link->prev is assured */
@@ -632,6 +635,8 @@ void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
if (link->next)
link->next->prev = link->prev;
g_free(link);
+ object->ref = NULL;
+ g_object_unref(object);
g_mutex_unlock(&opengl->objects_lock);
}
diff --git a/src/grits-plugin.c b/src/grits-plugin.c
index d79fdd1..60b3bbd 100644
--- a/src/grits-plugin.c
+++ b/src/grits-plugin.c
@@ -171,7 +171,7 @@ void grits_plugins_free(GritsPlugins *plugins)
g_debug("GritsPlugins: free");
for (GList *cur = plugins->plugins; cur; cur = cur->next) {
GritsPluginStore *store = cur->data;
- g_debug("GritsPlugin: freeing %s refs=%d->%d", store->name,
+ g_debug("GritsPlugins: freeing %s refs=%d->%d", store->name,
G_OBJECT(store->plugin)->ref_count,
G_OBJECT(store->plugin)->ref_count-1);
grits_plugins_free_store(store);
diff --git a/src/grits-viewer.c b/src/grits-viewer.c
index 52fbaf9..aa5c3a5 100644
--- a/src/grits-viewer.c
+++ b/src/grits-viewer.c
@@ -565,7 +565,6 @@ void grits_viewer_add(GritsViewer *viewer, GritsObject *object,
* @object: the object to remove
*
* Remove an object from the viewer.
- * The objects reference count is decremented.
*/
void grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
{
@@ -576,7 +575,6 @@ void grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
g_warning("GritsViewer: remove - Unimplemented");
object->viewer = NULL;
klass->remove(viewer, object);
- g_object_unref(object);
}
/****************
diff --git a/src/objects/grits-callback.c b/src/objects/grits-callback.c
index 36ba3af..2532c99 100644
--- a/src/objects/grits-callback.c
+++ b/src/objects/grits-callback.c
@@ -60,6 +60,7 @@ G_DEFINE_TYPE(GritsCallback, grits_callback, GRITS_TYPE_OBJECT);
static void grits_callback_finalize(GObject *cb)
{
g_debug("GritsCallback: finalize");
+ G_OBJECT_CLASS(grits_callback_parent_class)->finalize(cb);
}
static void grits_callback_init(GritsCallback *cb)
{
diff --git a/src/plugins/elev.c b/src/plugins/elev.c
index 7540a08..db7b977 100644
--- a/src/plugins/elev.c
+++ b/src/plugins/elev.c
@@ -343,8 +343,7 @@ 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);
+ 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 d833b43..6312f3b 100644
--- a/src/plugins/env.c
+++ b/src/plugins/env.c
@@ -376,7 +376,7 @@ static void grits_plugin_env_dispose(GObject *gobject)
if (env->viewer) {
for (GList *cur = env->refs; cur; cur = cur->next)
grits_viewer_remove(env->viewer, cur->data);
- g_list_free(env->refs);
+ g_list_free_full(env->refs, g_object_unref);
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 bb585e1..13f986c 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -248,6 +248,7 @@ static void grits_plugin_map_dispose(GObject *gobject)
map->viewer = NULL;
g_signal_handler_disconnect(viewer, map->sigid);
grits_viewer_remove(viewer, GRITS_OBJECT(map->tiles));
+ g_object_unref(map->tiles);
soup_session_abort(map->tms->http->soup);
//soup_session_abort(map->wms->http->soup);
g_thread_pool_free(map->threads, TRUE, TRUE);
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index d9d0891..8fe6e09 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -226,6 +226,7 @@ static void grits_plugin_sat_dispose(GObject *gobject)
sat->viewer = NULL;
g_signal_handler_disconnect(viewer, sat->sigid);
grits_viewer_remove(viewer, GRITS_OBJECT(sat->tiles));
+ g_object_unref(sat->tiles);
soup_session_abort(sat->wms->http->soup);
g_thread_pool_free(sat->threads, TRUE, TRUE);
while (gtk_events_pending())
diff --git a/src/plugins/test.c b/src/plugins/test.c
index 8a7e8a6..cfc999b 100644
--- a/src/plugins/test.c
+++ b/src/plugins/test.c
@@ -180,6 +180,9 @@ static void grits_plugin_test_dispose(GObject *_test)
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);
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]