[all-commits] [llvm/llvm-project] b494f6: [clangd] Fix crashing race in ClangdServer shutdow...

Sam McCall via All-commits all-commits at lists.llvm.org
Wed Dec 21 14:36:05 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b494f67f67968c50289148fb423a108607be83e9
      https://github.com/llvm/llvm-project/commit/b494f67f67968c50289148fb423a108607be83e9
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-12-21 (Wed, 21 Dec 2022)

  Changed paths:
    M clang-tools-extra/clangd/ClangdServer.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list