Skip to content

Commit 2c7ed74

Browse files
kjkclaude
andcommitted
fix crash in ClearTocBox due to re-entrant EN_CHANGE from SetText
Setting tocFilterEdit text to "" triggers EN_CHANGE synchronously, which re-enters ApplyTocFilter while tocLoaded is still true, causing access to freed TOC data. Move tocLoaded=false before SetText. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d29ec7b commit 2c7ed74

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/TableOfContents.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ void ClearTocBox(MainWindow* win) {
235235
return;
236236
}
237237

238+
// set tocLoaded to false before SetText("") because SetText triggers
239+
// EN_CHANGE synchronously which calls ApplyTocFilter() re-entrantly
240+
// and we need it to bail out early
241+
win->tocLoaded = false;
242+
238243
win->tocTreeView->Clear();
239244

240245
// clear filter state
@@ -245,7 +250,6 @@ void ClearTocBox(MainWindow* win) {
245250
}
246251

247252
win->currPageNo = 0;
248-
win->tocLoaded = false;
249253
}
250254

251255
void ToggleTocBox(MainWindow* win) {

0 commit comments

Comments
 (0)