? test-suite
Index: htmltext.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltext.c,v
retrieving revision 1.274
diff -u -r1.274 htmltext.c
--- htmltext.c	3 Feb 2005 17:18:43 -0000	1.274
+++ htmltext.c	24 Feb 2005 20:49:24 -0000
@@ -2097,21 +2097,15 @@
 } 
 
 static GList *
-remove_one (GList *list, GList *link)
-{
-	spell_error_destroy ((SpellError *) link->data);
-	return g_list_remove_link (list, link);
-}
-
-static GList *
 remove_spell_errors (GList *spell_errors, guint offset, guint len)
 {
 	SpellError *se; 
-	GList *cur, *cnext;
+	GList *cur=NULL, *toremove=NULL;
+
+	cur = g_list_copy (spell_errors);
 
-	cur = spell_errors;
 	while (cur) { 
-		cnext = cur->next;
+
 		se = (SpellError *) cur->data;
 		if (se->off < offset) {
 			if (se->off + se->len > offset) {
@@ -2120,20 +2114,34 @@
 				else
 					se->len -= len;
 				if (se->len < 2)
-					spell_errors = remove_one (spell_errors, cur);
+					toremove = g_list_append (toremove, se);
 			}
 		} else if (se->off < offset + len) {
-			if (se->off + se->len <= offset + len)
-				spell_errors = remove_one (spell_errors, cur);
-			else {
+			if (se->off + se->len <= offset + len) {
+				toremove = g_list_append (toremove, se);
+			} else {
 				se->len -= offset + len - se->off;
 				se->off  = offset + len;
 				if (se->len < 2)
-					spell_errors = remove_one (spell_errors, cur);
+					toremove = g_list_append (toremove, se);
 			}
 		}
- 		cur = cnext;
+
+ 		cur = g_list_next (cur);
   	} 
+
+	g_list_free (cur);
+
+	while (toremove)
+	{
+		se = (SpellError *) toremove->data;
+		spell_errors = g_list_remove_all (spell_errors, se);
+		spell_error_destroy ((SpellError *) se);
+		toremove = g_list_next (toremove);
+	}
+
+	g_list_free (toremove);
+
 	return spell_errors;
 }
 
