[Bug 32391] Correctly deal with removing name owner watches during dispatch of their callbacks
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Thu Dec 16 19:09:32 CET 2010
https://bugs.freedesktop.org/show_bug.cgi?id=32391
--- Comment #6 from Will Thompson <will.thompson at collabora.co.uk> 2010-12-16 10:09:32 PST ---
(In reply to comment #5)
> How about these?
>
> http://git.collabora.co.uk/?p=user/smcv/telepathy-glib-smcv.git;a=commitdiff;h=refs/heads/timeout
++
> http://git.collabora.co.uk/?p=user/smcv/telepathy-glib-smcv.git;a=shortlog;h=refs/heads/012-noc-fixes
+ for (i = 1; i <= array->len; i++)
+ {
+ _NameOwnerSubWatch *entry = &g_array_index (array,
+ _NameOwnerSubWatch, array->len - i);
+
+ if (entry->callback != NULL)
+ continue;
+
+ if (entry->destroy != NULL)
+ entry->destroy (entry->user_data);
+
+ g_array_remove_index (array, array->len - i);
+ }
As discussed in real life, this loop doesn't work; if you remove element 3 in
the array, then element 2 will not be examined.
The fix is to iterate like this:
for (i = array->len; i > 0; i--)
{
_NameOwnerSubWatch *entry = &g_array_index (array,
_NameOwnerSubWatch, i - 1);
...
}
The test can test this by doing something clever in its GDestroyNotify.
The other loop that iterates backwards should also be changed to iterate like
this. It's clearer.
--
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the telepathy-bugs
mailing list