From 0df2c1fa7ca2423fb1f52caf18f23a4f370aacfa Mon Sep 17 00:00:00 2001 From: Jim Nelson Date: Mon, 12 Aug 2013 12:52:45 -0700 Subject: [PATCH] Fixes crash when removing unfulfilled during writebehind operation Encountered this morning -- list operation had unfulfilled emails waiting for network operations but folder normalization determined they were missing and used a writebehind to remove them from the operation, but the loop to remove them explodes (can't do a remove within a foreach). This loop solves that problem. --- .../imap-engine-abstract-list-email.vala | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala index 05041631..6b654203 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala @@ -95,8 +95,18 @@ private abstract class Geary.ImapEngine.AbstractListEmail : Geary.ImapEngine.Sen } // remove from unfulfilled list, as there's nothing to fetch from the server - foreach (Geary.Email.Field field in unfulfilled.get_keys()) - unfulfilled.remove(field, id); + // this funky little loop ensures that all mentions of the EmailIdentifier in + // the unfulfilled MultiMap are removed, but must restart loop because removing + // within a foreach invalidates the Iterator + bool removed = false; + do { + removed = false; + foreach (Geary.Email.Field field in unfulfilled.get_keys()) { + removed = unfulfilled.remove(field, id); + if (removed) + break; + } + } while (removed); return true;