[telepathy-mission-control/master] McdDispatcher: don't iterate over a channel list that will be modified during iteration
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue May 26 10:22:31 PDT 2009
This fixes a valgrind warning.
---
src/mcd-dispatcher.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 9aa3e6b..463f584 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1357,9 +1357,15 @@ _mcd_dispatcher_context_abort (McdDispatcherContext *context,
{
GList *list;
- g_return_if_fail(context);
+ g_return_if_fail (context);
- for (list = context->channels; list != NULL; list = list->next)
+ /* make a temporary copy, which is destroyed during the loop - otherwise
+ * we'll be trying to iterate over context->channels at the same time
+ * that mcd_mission_abort results in modifying it, which would be bad */
+ list = g_list_copy (context->channels);
+ g_list_foreach (list, (GFunc) g_object_ref, NULL);
+
+ while (list != NULL)
{
McdChannel *channel = MCD_CHANNEL (list->data);
@@ -1369,6 +1375,9 @@ _mcd_dispatcher_context_abort (McdDispatcherContext *context,
/* FIXME: try to dispatch the channels to another handler, instead
* of just aborting them */
mcd_mission_abort (MCD_MISSION (channel));
+
+ g_object_unref (channel);
+ list = g_list_delete_link (list, list);
}
}
--
1.5.6.5
More information about the telepathy-commits
mailing list