[clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing
In principle it's OK for stdlib-indexing tasks to run after the TUScheduler is destroyed, as mostly they just update the dynamic index. We do drain the stdlib-indexing queue before destroying the index. However the task captures references to the PreambleCallbacks object, which is owned by the TUScheduler. Once this is destroyed (explicitly, early in ~ClangdServer) an outstanding stdlib-indexing task may use-after-free. The fix here is to avoid capturing references to the PreambleCallbacks. Alternatives would be to have TUScheduler (exclusively) not own its callbacks so they could live longer, or explicitly stopping the TUScheduler instead of early-destroying it. These both seem more invasive. See https://reviews.llvm.org/D115232 for some more context. Differential Revision: https://reviews.llvm.org/D140486
Loading
Please sign in to comment