Without this patch the old index could be freed, but there still could be tries to access it via the function returned by SwapIndex::indexedFiles() call.
This leads to hard to reproduce clangd crashes at code completion.
This patch keeps the old index alive until the function returned by SwapIndex::indexedFiles() call is alive.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
Thanks, I'd seen these crashes but not manage to track down yet!
LG with one fix
| clang-tools-extra/clangd/index/Index.cpp | ||
|---|---|---|
| 81–84 | Calling snapshot() twice introduces a race - we may keep the wrong one alive. Evaluate snapshot first into a variable, then call indexedFiles, then move both into the lambda? | |
clang-format: please reformat the code
- return [ KeepAlive = snapshot(), - IndexedFiles = snapshot()->indexedFiles() ](llvm::StringRef File) { - return IndexedFiles(File); - }; + return [KeepAlive = snapshot(), IndexedFiles = snapshot()->indexedFiles()]( + llvm::StringRef File) { return IndexedFiles(File); };