Skip to content

Commit d377aa8

Browse files
CzarekCzarek
authored andcommitted
Fixed the renderer process crashing, removing javascript callbacks
in OnContextReleased caused an infinite loop due to misuse of the iterator when calling std::map.erase().
1 parent d7d69fa commit d377aa8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cefpython/cef3/subprocess/javascript_callback.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ void RemoveJavascriptCallbacksForFrame(CefRefPtr<CefFrame> frame) {
8585
int64 frameId = frame->GetIdentifier();
8686
while (it != g_jsCallbackMap.end()) {
8787
if (it->second.first->GetIdentifier() == frameId) {
88-
g_jsCallbackMap.erase(it);
88+
// Pass current iterator and increment it after passing
89+
// to the function, but before erase() is called, this
90+
// is important for it to work in a loop. You can't do this:
91+
// | if (..) erase(it);
92+
// | ++it;
93+
// This would cause an infinite loop.
94+
g_jsCallbackMap.erase(it++);
8995
DebugLog("Renderer: RemoveJavascriptCallbacksForFrame(): " \
9096
"removed js callback from the map");
97+
} else {
98+
++it;
9199
}
92-
++it;
93100
}
94101
}

0 commit comments

Comments
 (0)