aboutsummaryrefslogtreecommitdiff
path: root/sysutils/synergy/files/patch-lib__platform__CXWindowsClipboard.cpp
blob: dd40e23c82d3f9cdcf8d4aece4192b00864edc8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--- lib/platform/CXWindowsClipboard.cpp.orig	2006-04-02 09:47:03.000000000 +0800
+++ lib/platform/CXWindowsClipboard.cpp	2008-10-06 15:52:39.000000000 +0800
@@ -219,7 +219,7 @@
 		if (reply->m_replied && reply->m_property == property) {
 			// if reply is complete then remove it and start the
 			// next one.
-			pushReplies(index, replies, index2);
+			pushReplies(index->first, replies, index2);
 			return true;
 		}
 	}
@@ -928,17 +928,23 @@
 {
 	// send the first reply for each window if that reply hasn't
 	// been sent yet.
-	for (CReplyMap::iterator index = m_replies.begin();
-								index != m_replies.end(); ++index) {
-		assert(!index->second.empty());
-		if (!index->second.front()->m_replied) {
-			pushReplies(index, index->second, index->second.begin());
+	CReplyMap::iterator index = m_replies.begin();
+	while (index != m_replies.end()) {
+		// increment index before calling pushReplies(...) as
+		// pushReplies(...) normally erases the member of the map, that
+		// index points to, invalidating index as iterator.
+		Window requestor = index->first;
+		CReplyList& replies = index->second;
+		index++;
+		assert(!replies.empty());
+		if (!replies.front()->m_replied) {
+			pushReplies(requestor, replies, replies.begin());
 		}
 	}
 }
 
 void
-CXWindowsClipboard::pushReplies(CReplyMap::iterator mapIndex,
+CXWindowsClipboard::pushReplies(Window requestor,
 				CReplyList& replies, CReplyList::iterator index)
 {
 	CReply* reply = *index;
@@ -957,9 +963,8 @@
 	// and stop watching the requestor for events.
 	if (replies.empty()) {
 		CXWindowsUtil::CErrorLock lock(m_display);
-		Window requestor = mapIndex->first;
 		XSelectInput(m_display, requestor, m_eventMasks[requestor]);
-		m_replies.erase(mapIndex);
+		m_replies.erase(requestor);
 		m_eventMasks.erase(requestor);
 	}
 }