From 07267bf096978a528a02bfa9d12aec2d6f5de541 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 3 Jan 2001 16:05:39 +0000 Subject: [PATCH] Unref callback->cb_data if it was still set when the source is freed. Wed Dec 13 20:41:49 2000 Owen Taylor * gmain.c (g_source_unref_internal): Unref callback->cb_data if it was still set when the source is freed. (Usually, this will be done by g_source_destroy.) --- ChangeLog | 6 ++++++ ChangeLog.pre-2-0 | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-2 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ glib/gmain.c | 15 ++++++++++----- gmain.c | 15 ++++++++++----- 10 files changed, 68 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0fb944438..32fd7d2be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0fb944438..32fd7d2be 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Wed Dec 13 20:41:49 2000 Owen Taylor + + * gmain.c (g_source_unref_internal): Unref callback->cb_data + if it was still set when the source is freed. (Usually, this + will be done by g_source_destroy.) + 2001-01-02 Dan Winship * garray.h (g_array_append_val, g_array_prepend_val, diff --git a/glib/gmain.c b/glib/gmain.c index 5f2e2a726..61957e213 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -1173,9 +1173,8 @@ g_source_unref_internal (GSource *source, GMainContext *context, gboolean have_lock) { - gpointer cb_data = NULL; - GSourceCallbackFuncs *cb_funcs = NULL; - GSList *tmp_list; + gpointer old_cb_data = NULL; + GSourceCallbackFuncs *old_cb_funcs = NULL; g_return_if_fail (source != NULL); @@ -1185,6 +1184,12 @@ g_source_unref_internal (GSource *source, source->ref_count--; if (source->ref_count == 0) { + old_cb_data = source->callback_data; + old_cb_funcs = source->callback_funcs; + + source->callback_data = NULL; + source->callback_funcs = NULL; + if (context && !SOURCE_DESTROYED (source)) { g_warning (G_STRLOC ": ref_count == 0, but source is still attached to a context!"); @@ -1204,12 +1209,12 @@ g_source_unref_internal (GSource *source, if (!have_lock && context) UNLOCK_CONTEXT (context); - if (cb_data) + if (old_cb_funcs) { if (have_lock) UNLOCK_CONTEXT (context); - cb_funcs->unref (cb_data); + old_cb_funcs->unref (old_cb_data); if (have_lock) LOCK_CONTEXT (context); diff --git a/gmain.c b/gmain.c index 5f2e2a726..61957e213 100644 --- a/gmain.c +++ b/gmain.c @@ -1173,9 +1173,8 @@ g_source_unref_internal (GSource *source, GMainContext *context, gboolean have_lock) { - gpointer cb_data = NULL; - GSourceCallbackFuncs *cb_funcs = NULL; - GSList *tmp_list; + gpointer old_cb_data = NULL; + GSourceCallbackFuncs *old_cb_funcs = NULL; g_return_if_fail (source != NULL); @@ -1185,6 +1184,12 @@ g_source_unref_internal (GSource *source, source->ref_count--; if (source->ref_count == 0) { + old_cb_data = source->callback_data; + old_cb_funcs = source->callback_funcs; + + source->callback_data = NULL; + source->callback_funcs = NULL; + if (context && !SOURCE_DESTROYED (source)) { g_warning (G_STRLOC ": ref_count == 0, but source is still attached to a context!"); @@ -1204,12 +1209,12 @@ g_source_unref_internal (GSource *source, if (!have_lock && context) UNLOCK_CONTEXT (context); - if (cb_data) + if (old_cb_funcs) { if (have_lock) UNLOCK_CONTEXT (context); - cb_funcs->unref (cb_data); + old_cb_funcs->unref (old_cb_data); if (have_lock) LOCK_CONTEXT (context);